Clear and concise description of the problem
When resolving a worker URL, it’s resolved relative to the current location. If a worker is loaded from node_modules, the full relative path needs to be specified. This may cause various issues:
- Resolving up to the project root and then into
node_modules looks messy.
- In a mono repo, there may be multiple
node_modules folders. Seemingly unrelated dependency changes may change the location of the worker code to resolve.
- If the worker is instantiated from a dependency, it needs to know where its dependencies are installed.
Suggested solution
Instead of the following:
new Worker(new URL('../../../../../node_modules/monaco-editor/esm/vs/editor/editor.worker', import.meta.url));
Let users write the following code:
new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker', import.meta.url));
It would be nice this behaviour is kept, but as a fallback, the dependency is resolved from node_modules.
Alternative
No response
Additional context
Webpack also tries to resolve this from both a local file path and node_modules. Migrating to Vite is how I ran into this issue.
Validations