-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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] npx doesn't work when in child workspace #2826
Comments
I don't think this is something that was ever truly reliable. If you're expecting to run a local binary, it should be a direct dep/devDep. If anything, it's a bug that bins are created at all for transitive deps. |
This can be replicated:
|
Ah, in the context of workspaces, i see what you mean. The bins should surely not be hoisted to the parent, even if the module itself is. |
Can replicate & we're discussing internally how to fix this bug |
I have some ideas:
|
The last option makes the most sense to me; if you wanted to run a bin from the root it'd be in the root's package.json. |
What if there are two child projects which has That's why I think the third option would be better than the fourth. |
Hoisting the dependency itself would make sense - but not the bin. |
In a monorepo, I would like to have The only solution which would match this requirement would be 1 and 2. But now I thought in a new one which builds on 4:
Now, this is the one which makes more sense to me. |
Yes, option 5 is what I'm expecting, with npm's current hoisting model. |
Apart from that, I think option 1 could be implemented as well, together with 5, and it would be harmless. No? It would only make |
Either or both could be done, yes, but workspace correctness would still require option 2, 3, 4, or 5. |
That's the current behavior today: https://github.com/npm/run-script/blob/2a2f1b637ffa2463a82df477e17ea4e146682f5b/lib/set-path.js#L19 I'm not sure if there was something that was fixed between your original post and now but this is working as intended when I test with npm@7.10.0, I have the following structure (with
it works as intended when I This is what both diff --git a/a/package.json b/a/package.json
new file mode 100644
index 0000000..c845857
--- a/a/package.json
+++ b/a/package.json
+{
+ "name": "a",
+ "version": "1.0.0",
+ "dependencies": {
+ "@ruyadorno/create-index": "^1.0.0"
+ }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..23dd3e2
--- a/package.json
+++ b/package.json
+{
+ "name": "test-npx-workspaces",
+ "workspaces": [
+ "a"
+ ]
+} I'll sync up internally with @darcyclarke again to see if he can still reproduce it but would appreciate if you can give it a try again @felipecrs, vlw! |
The issue can still be replicated with the steps I suggested:
If that would be the case, the example above would have worked. Perhaps such logic only applies to |
This comment has been minimized.
This comment has been minimized.
@ruyadorno I'm sorry, but did you note that > gitpod /workspace/megatar/website $ npx typedoc --version
Need to install the following packages:
typedoc
Ok to proceed? (y)
> gitpod /workspace/megatar/website $ cd ..
> gitpod /workspace/megatar $ npx typedoc --version
Info: Loaded plugin /workspace/megatar/node_modules/typedoc-plugin-markdown
Info: Loaded plugin /workspace/megatar/node_modules/typedoc-plugin-merge-modules
TypeDoc 0.20.32
Using TypeScript 4.2.4 from /workspace/megatar/node_modules/typescript/lib So, the issue remains valid. |
@felipecrs you're right! I totally got confused by the name of the packages there, now I realize the actual package that install the I believe I'm on the right track now and I think this issue should be solved by looking up as you suggested in your |
@ljharb I'm carefully avoiding that topic here since I believe it's going to be better addressed as part of the upcoming workspaces-revamp RFC we have been alluding to in the last OpenRFC meetings 😉 That said, I'm not excluding the possibility the solution to the problem surfaced by this issue might have to pass through that major overhaul. For now I'm exploring the possibility of fixing this by simply reusing the lookup algo from run-script (which btw might not be so simple) either way I'll keep you posted 😊 Thanks! |
Thanks, as long as it's not ignored :-) |
Currently @npmcli/run-script already supports this walk up lookup logic that allows any nested folder to use a bin that is located inside a node_modules/.bin folder higher in the directory tree. This commit adds the same logic from: https://github.com/npm/run-script/blob/47a4d539fb07220e7215cc0e482683b76407ef9b/lib/set-path.js#L24-L28 to libnpmexec so that users may use a binary from a dependency of a nested workspace in the context of that workspaces' folder. Fixes: npm/cli#2826
@felipecrs I also forgot to mention that alternatively you can also use $ npm exec -w website -- docusaurus so you can also use that while you wait for the fix 😊 |
Thank you @ruyadorno. Very nice feature. |
Currently @npmcli/run-script already supports this walk up lookup logic that allows any nested folder to use a bin that is located inside a node_modules/.bin folder higher in the directory tree. This commit adds the same logic from: https://github.com/npm/run-script/blob/47a4d539fb07220e7215cc0e482683b76407ef9b/lib/set-path.js#L24-L28 to libnpmexec so that users may use a binary from a dependency of a nested workspace in the context of that workspaces' folder. Fixes: npm/cli#2826
Current Behavior:
If I run
npx <binary>
of a binary installed by a child'spackage.json
, it doesn't find the binary as npm v7 now install the binaries under the parentnode_modules
.Expected Behavior:
This used to work, as there was no workspaces concept before and therefore all the projects were linking binaries to their
node_modules
.Steps To Reproduce:
Should be simple.
Environment:
Suggestion
I think this should not be fixed by
npx
itself, but instead,npm
should create symlinks under the children'snode_modules/.bin
at least for the packages referenced in the children'spackage.json
.The text was updated successfully, but these errors were encountered: