Skip to content

Worker relative path resolution fails with nested folders #21686

@jacogr

Description

@jacogr
  • Version: 10.6
  • Platform: Darwin Kernel Version 17.3.0
  • Subsystem: workers

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 the packages/*/ 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'), where worker.js and the index.js is right alongside each other.

events.js:167
      throw er; // Unhandled 'error' event
      ^
Error: Cannot find module '/Users/jacogreeff/Projects/polkadot/node-worker-path/worker.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at MessagePort.port.on (internal/worker.js:425:27)
    at MessagePort.emit (events.js:182:13)
    at MessagePort.onmessage (internal/worker.js:66:8)
Emitted 'error' event at:
    at Worker.[kOnErrorMessage] (internal/worker.js:296:10)
    at Worker.[kOnMessage] (internal/worker.js:306:37)
    at MessagePort.Worker.(anonymous function).on (internal/worker.js:243:57)
    at MessagePort.emit (events.js:182:13)
    at MessagePort.onmessage (internal/worker.js:66:8)
error Command failed with exit code 1.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    workerIssues and PRs related to Worker support.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions