Open zner0L opened 1 year ago
I tried passing options to the Worker
constructor such as env: { NODE_OPTIONS: "--import tsx" }
and execArgv: ["--import", "tsx"]
but neither of those worked and then I found nodejs/node#47747 (ESM loaders cannot be defined via Worker option...)
I think this is really a Node bug or design issue. If a loader was specified at the top level, Node should be using that automatically for Worker threads.
Other notes
typescript
see nodejs/node#49704module.register()
API at nodejs/node#50392I'm facing the same issue as you do, and I had to stick with tsx v3.13.0
I've found a temporary workaround: while developing, you'll want your worker to load tsx/cli
instead, then pass the actual script you wanna run as an argv
, like so:
const tsx = new URL(import.meta.resolve('tsx/cli'));
const worker = new Worker(tsx, {env: SHARE_ENV, argv: ['./your/script.ts']});
Looked into this. Sounds like this is a limitation on Node's end? Marking this as blocked
This is an issue for node v18.19.0 too
I got an error with this Error: listen EADDRINUSE: address already in use
.
I've found a temporary workaround: while developing, you'll want your worker to load
tsx/cli
instead, then pass the actual script you wanna run as anargv
, like so:const tsx = new URL(import.meta.resolve('tsx/cli')); const worker = new Worker(tsx, {env: SHARE_ENV, argv: ['./your/script.ts']});
This is currently a limitation in Node.js. The issue was closed without resolution: https://github.com/nodejs/node/issues/47747
They currently don't think the performance cost is worth it, but are open to learning about more use-cases.
I have requested for it to be re-opened. If you'd like loaders to be supported in Workers,
your best course of action is to share your use-case there.
Again, don't just say "plz fix". Share your use-case in https://github.com/nodejs/node/issues/47747.
Our use case is running tsx --watch
as dev server for a typescript project who use a Worker
for specific tasks and run tests with vitest
For now the only fix we found was to stick with node 20.9.0
and tsx 3.13.0
We have to start our tests script with NODE_OPTIONS='--loader tsx --no-warnings' vitest --run
Our use case is using tsx with ava. Similarly, we have to downgrade for now.
I'm not using any worker threads, but just:
import fs from 'node:fs'
import LinguistLanguages from 'linguist-languages'
import { SupportLanguage } from 'prettier'
https://github.com/un-ts/prettier/actions/runs/7152253084/job/19477387552?pr=327#step:5:96
See source codes at https://github.com/un-ts/prettier/blob/master/scripts/languages.ts
This is blocked by Node.js. Please contribute constructively in https://github.com/nodejs/node/issues/47747
Looks like it's been re-opened with a potential solution that could use help.
Locking thread until resolved in Node.
https://github.com/nodejs/node/issues/47747 was closed without fix
I'm going to lock this issue again to avoid unproductive comments and encourage actionable steps.
Since the root problem lies within Node, the conversation will have to happen there. If the Node issue was closed without a resolution, I suggest filing a new one with a clear, reproducible example to demonstrate how the problem still exists.
Problem
I was tracking https://github.com/esbuild-kit/tsx/issues/330 closely and was very happy for you to fix it with https://github.com/esbuild-kit/tsx/pull/337 and release so quickly, but I just now tested it with loading worker threads and that fails with
ERR_UNKNOWN_FILE_EXTENSION
.Minimal example:
Result:
Expected behavior
If I run the minimal example with tsx
v3.13.0
the output is as expected (though with warnings):Minimal reproduction URL
Included in issue
Version
v3.14.0
Node.js version
v20.8.0
Package manager
yarn
Operating system
Linux
Contributions