Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yarn proto2ts fails on Node 22 #1114

Open
vecerek opened this issue Sep 29, 2024 · 1 comment
Open

yarn proto2ts fails on Node 22 #1114

vecerek opened this issue Sep 29, 2024 · 1 comment

Comments

@vecerek
Copy link
Contributor

vecerek commented Sep 29, 2024

Integration test compilation fails during the execution of the yarn proto2ts command with SyntaxError: Invalid regular expression flags.

Steps to reproduce

  1. Delete the ts-proto-protoc image (if it exists).
  2. yarn proto2ts
  3. Observe the errors

Example error

Test ./output-fromJSON-only
decode.proto:3:1: warning: Import google/protobuf/wrappers.proto is unused.
/ts-proto/integration/protoc-gen-ts_proto:5
?filePath=/ts-proto/integration/protoc-gen-ts_proto
          ^

SyntaxError: Invalid regular expression flags
    at wrapSafe (node:internal/modules/cjs/loader:1469:18)
    at Module._compile (node:internal/modules/cjs/loader:1491:20)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Object.transformer (/ts-proto/node_modules/tsx/dist/register-C1urN2EO.cjs:2:889)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
    at Module._load (node:internal/modules/cjs/loader:1127:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at cjsLoader (node:internal/modules/esm/translators:329:5)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:260:7)

Node.js v22.9.0
--ts_proto_out: protoc-gen-ts_proto: Plugin failed with status code 1.

Workaround

  1. Delete the ts-proto-protoc image
  2. Change FROM node:current-slim to FROM node:20-bullseye-slim in protoc.Dockerfile.
  3. yarn proto2ts
@stephenh
Copy link
Owner

Wow, that's weird; I really can't figure out who is to blame.

Turning on NODE_DEBUG=module gets a little more output like:

MODULE 9: Module._load REQUEST worker_threads parent: /ts-proto/node_modules/esbuild/lib/main.js
MODULE 9: load built-in module worker_threads
MODULE 9: looking for "/ts-proto/integration/protoc-gen-ts_proto" in ["/root/.node_modules","/root/.node_libraries","/usr/local/lib/node"]
MODULE 9: load "/ts-proto/integration/protoc-gen-ts_proto" for module "data:text/javascript,%23!%2Fusr%2Fbin%2Fenv%20node%0A(()%3D%3E%7B%0Arequire(%22..%2Fsrc%2Fplugin%22)%3B%0A%7D)()%0A?filePath=%2Fts-proto%2Fintegration%2Fprotoc-gen-ts_proto"
/ts-proto/integration/protoc-gen-ts_proto:5
?filePath=/ts-proto/integration/protoc-gen-ts_proto
          ^

SyntaxError: Invalid regular expression flags
    at wrapSafe (node:internal/modules/cjs/loader:1469:18)
    at Module._compile (node:internal/modules/cjs/loader:1491:20)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Object.transformer (/ts-proto/node_modules/tsx/dist/register-DpmFHar1.cjs:2:953)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
    at Module._load (node:internal/modules/cjs/loader:1127:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)

And it seems like it's this data:text/javascript,.../usr/bin/env but url encoded that node says "has an invalid regexp flag".

Not sure if this is tsx doing something wrong, or node's own /usr/env/env node support going wrong; probably the latter?

I scanned through tsx and node open issues and didn't find anything...

If I update ./integration/protoc-gen-ts_proto to just console.log:

#!/usr/bin/env node
// require('../src/plugin')
console.log("HELLO!");

Then I can run it directly like ./protoc-gen-ts_proto and see HELLO

But if I run ./update-code.sh simple and have ./protoc-gen-ts_proto invoked via protoc, I get the same:

MODULE 859119: load "/home/stephen/other/ts-proto/integration/protoc-gen-ts_proto" for module "data:text/javascript,%23!%2Fusr%2Fbin%2Fenv%20node%0A(()%3D%3E%7B%0Aconsole.log(%22HELLO!%22)%3B%0A%7D)()%0A?filePath=%2Fhome%2Fstephen%2Fother%2Fts-proto%2Fintegration%2Fprotoc-gen-ts_proto"

What's interesting is that it looks like the contents of ./protoc-gen-ts_proto are basically being URL encoded into this data:text/javascript,..., I assume by the /usr/bin/env node infra...

But that someone that is working just fine when invoking the file manually, but not working when protoc invokes it from within its plugin system... 🤔

stephenh added a commit that referenced this issue Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants