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

JS Decorator Support #645

Open
transitive-bullshit opened this issue Jun 9, 2024 · 2 comments
Open

JS Decorator Support #645

transitive-bullshit opened this issue Jun 9, 2024 · 2 comments

Comments

@transitive-bullshit
Copy link
Owner

When building and running the examples locally, you may run into this JS decorator error if your env isn't set up properly.

If you try to run tsx bin/scratch.ts or any of the example executables directly like tsx examples/ai-sdk/weather.ts – without transpiling from TS to JS, you may get the following error:

node:internal/modules/run_main:115
    triggerUncaughtException(
    ^
Error [TransformError]: Transform failed with 1 error:
/Users/tfischer/dev/modules/agentic/src/tools/search-and-crawl.ts:24:2: ERROR: Transforming JavaScript decorators to the configured target environment ("node22.2.0") is not supported yet
    at failureErrorWithLog (/Users/tfischer/.nvm/versions/node/v22.2.0/lib/node_modules/tsx/node_modules/esbuild/lib/main.js:1651:15)
    at /Users/tfischer/.nvm/versions/node/v22.2.0/lib/node_modules/tsx/node_modules/esbuild/lib/main.js:849:29
    at responseCallbacks.<computed> (/Users/tfischer/.nvm/versions/node/v22.2.0/lib/node_modules/tsx/node_modules/esbuild/lib/main.js:704:9)
    at handleIncomingPacket (/Users/tfischer/.nvm/versions/node/v22.2.0/lib/node_modules/tsx/node_modules/esbuild/lib/main.js:764:9)
    at Socket.readFromStdout (/Users/tfischer/.nvm/versions/node/v22.2.0/lib/node_modules/tsx/node_modules/esbuild/lib/main.js:680:7)
    at Socket.emit (node:events:520:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:191:23)

Node.js v22.2.0

This is because this project uses ECMAScript Decorators which are a stage-3 proposal and ECMAScript Decorator Metadata which is possibly also a stage-3 proposal, though thats less clear. Note that this project does not use TypeScript's unofficial legacy decorator support, which is why experimentalDecorators is not enabled.

Both TypeScript and esbuild support these modern decorators, but they're still propagating support across the ecosystem to various build tools, so if you want to contribute to this library, you'll need the latest versions of them. We use a pnpm override to ensure that all dependencies like tsx and vitest use the latest version of esbuild.

Once the project is transpiled to dist, the resulting JS code doesn't use this fancy syntax, so it should work with any modern JS runtime (e.g., node >= 18, bun, deno, etc).

As a workaround for testing things, you can either run npx tsx bin/scratch.ts or node --disable-warning=ExperimentalWarning --disable-warning=DeprecationWarning --loader ts-node/esm bin/scratch.ts`, both of which do roughly the same thing.

@CASSIOSOUZA
Copy link

Olá estou com esse mesmo problema porem a solução no meu caso não funcionou. Teria alguma outra forma de rodar a aplicação ?

@transitive-bullshit
Copy link
Owner Author

Olá estou com esse mesmo problema porem a solução no meu caso não funcionou. Teria alguma outra forma de rodar a aplicação ?
(translation) Hello, I have the same problem but the solution in my case didn't work. Is there any other way to run the application?

@CASSIOSOUZA which version of node.js and are you using? Are you using tsx, and if so which version? Give me as much info as possible about your environment and how you're trying to run the built-in examples.

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