-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[BUG] Arbitrary package hoisting on NPM workspaces can lead to issues #5840
Comments
|
That's the issue with workspaces indeed :) If packages are not at the same level when run there are require issues which seems like a fatal flaw of the workspaces solution? Or perhaps there's something I'm missing? |
I'm confused. A relative In workspaces, from root, a nested package should be required with a bare specifier - ie, |
@ljharb that's just to illustrate the point and perhaps is not the best way to portray this. As the most recent example you might see this PR which is failing WordPress/gutenberg#45697 I can reproduce that the issue (at least locally) is that the new package gets installed within the package The underlying issue (maybe?) is that packages are (seemingly) arbitrarily hoisted/not-hoisted which can lead to non-deterministic runs |
require also looks upwards in every node_modules folder til it hits /, so hoisting shouldn’t affect anything either. Apologies I’m on mobile and can’t check out your repro repo; I’m sure it will be a great help to one of the npm folks :-) |
So if it wasn't hoisted then it'd be fine, the issue comes when:
In this case runner tries to find the task and fails. |
require
doesn't seem to respect process.cwd()
on NPM workspaces
This does not seem like an npm bug. This is a bug with a package requiring a dependency not declared in its own package.json. If you want to require a dependency it has to be declared as either a dependency or a peer dependency. Your |
@wraithgar that is not what's happening here: WordPress/gutenberg#45697 for example you can see that for some reason, the only dependency that's now nested within
As I hinted before, that repo might not be the best. I thought it was a bug in Node with In the case of
Now when I hope I have painted the issue correctly now and it can be reopened and considered. |
@wraithgar @ljharb could this be reopened please? |
Funny enough, I just came across this exact same issue independently of @Antonio-Laguna in the same repository. I was attempting to update Before, To clarify on the explicit dependency point, the dependencies are explicit:
At every step of the process, the internal monorepo dependencies are 100% explicit. Even the root This is either a bug with npm or eslint, unless explicit internal monorepo dependencies aren't supported |
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
NPM workspaces install dependencies at different levels of the app. When things are
require
d you can get errors because things aren't at the same level.When root dependency tries to require nested dependency there're issues. While you can often hoist dependencies up this is not always desirable.
It does not work if nested calls to root that tries to find a nested dependency,
require.resolve.paths
show thatcwd
isn't included on those paths.Expected Behavior
require
works as long in, either way, no matter where npm decides to install the dependency, or we should be able to set where packages are installed.See nodejs/node#43429
Steps To Reproduce
This is reproducible in this small repository: https://github.com/Antonio-Laguna/node-workspaces-bug
Environment
The text was updated successfully, but these errors were encountered: