-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Worker relative path resolution fails with nested folders #21686
Comments
Fwiw, there’s some prior discussion around this in #21407 … I agree with the behaviour that you’d expect, but that’s not quite easy to implement. I’d personally recommend always using absolute paths; /cc @nodejs/workers |
cc @itaysabato |
Yes, I did swap to absolute paths in the real code and it works as expected. So there is a work-around, which is great - I actually started with absolutes in 10.5, then swapped to relatives with 10.6 and then back to absolutes when that didn't quite work as expected... ;) I however still logged this, since the behavior is not quite what anybody would expect here. I appreciate the complexity of doing it consistently. |
@jacogr I respectfully disagree that it is not what "anybody" would expect. I think resloving relative to CWD is actually what most people would expect (I am not the only one who thinks this, though I understand there may not be a consensus). For example, child_process.fork() starts a module in a separate process similarly to how |
@itaysabato Sure. There are inconsistencies in this - In the same file, if I would do a So definitely not "anybody" & "everybody" - sadly there are surprises around every corner. |
Is there anything to do here? It's not clear to me from the conversation if there's an improvement to be made for relative paths or not. |
@nodejs/workers ^^^^^^ |
So far as ES modules are concerned, contextual loading is a primary area of spec work at the moment, with various proposals and solutions available for these exact use cases, applying to more than just workers. The directions here are still unclear with many possibilities, but it does seem pretty certain that in an ES modules context this problem will be solvable using the contextual approaches that emerge, provided we are open to these directions. |
I'm going to close this as "working as intended". While I agree that it would be more intuitive to resolve relative to the file that instantiated the worker, relative to cwd has always been the documented behavior and it's possible to get the other behavior more easily from inside the calling module (with |
Relative path resolution in
worker_threads
does not quite do what is expected. I created a simple repo that simulates a yarn workspace environment where the issue is manifesting. However while thepackages/*/
structure is there, there is no actual references between workspace packages, rather just 3 files that reference each other.https://github.com/jacogr/node-worker-path
To Reproduce just run
npm run test
. Basically where packages/worker/src/index.js references the worker (which is in the same directory), the creation fails - Node is looking for the file in the root.File does a
const worker = new Worker('./worker.js')
, whereworker.js
and theindex.js
is right alongside each other.It looks for
Cannot find module '...node-worker-path/worker.js
while the correct path in this case would be....node-worker-path/packages/src/worker.js
The text was updated successfully, but these errors were encountered: