-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Yarn workspace incorrectly resolves node_modules path during script execution of workspace dependencies #4564
Comments
Apparently this is windows only. Long and short of it is that, when creating the output shim, we compute the path relative to the root. So in my example, we compute the relative path from 'test2' as a folder directly under the workspace to the node_module folder of the workspace. from - ..\workspaceModuleBug\test2\node_modules\.bin ..However, before executing the spawned process, we add the nested path (underneath the node_module\test2\node_module): ...\workspaceModuleBug\node_modules\test2\node_modules\.bin So note, we wrote a CMD that understands the relative path between test2\node_module\.bin and the workspace's node_modules, but we add the installed module, node_modules\test2\node_modules to the path. So, when we execute the spawned child process, it fails because the path incorrectly resolves to: ...\workspaceModuleBug\node_modules\node_modules\[package]\dist\index.js Note, the duplicate node_module. If I can get advice on the proper place to patch this, I will be happy to try but I am unsure if altering the path we create is a good idea. (or how to tell when I should) in the current code. Also, since the same physical package installation will now be available via two different physical paths, I don't know we can fulfill both requirements with the current template of the CMD file as generated by cmd-shim. So it would either need to be more intelligent or would only work in one of the two circumstances. |
This line is where the potentially errant path is added: yarn/src/util/execute-lifecycle-script.js Line 152 in d64512c
I am not saying this is necessarily where the fix should go but I am hoping it provides a quick way for someone to review and let me know a valid way to proceed. |
Wondering if anyone had further thoughts on this? |
Still an issue in yarn 1.7.0. Have not found any workaround yet. @BYK is this still on your list? It seems like a rather big blocker for using workspaces. |
We have the same issue with yarn 1.9.4, |
This seems to be Windows only problem, so I wonder if junctions are somehow not properly handled which causes node_modules being added twice to the bin path?
UpdateI was able to fix this by adding a |
I was able to fix this by adding a |
I'm facing same issue. |
- updated the `postinstall` scripts for both `cortext-debug` and `cpp-debug`. - updated the scripts as a workaround to a known yarn issue on windows (yarnpkg/yarn#4564) Signed-off-by: vince-fugnitto <[email protected]>
- updated the `postinstall` scripts for both `cortext-debug` and `cpp-debug`. - updated the scripts as a workaround to a known yarn issue on windows (yarnpkg/yarn#4564) Signed-off-by: vince-fugnitto <[email protected]>
- updated the `postinstall` scripts for both `cortext-debug` and `cpp-debug`. - updated the scripts as a workaround to a known yarn issue on windows (yarnpkg/yarn#4564) Signed-off-by: vince-fugnitto <[email protected]>
- updated the `postinstall` scripts for both `cortext-debug` and `cpp-debug`. - updated the scripts as a workaround to a known yarn issue on windows (yarnpkg/yarn#4564) Signed-off-by: vince-fugnitto <[email protected]>
- updated the `postinstall` scripts for both `cortext-debug` and `cpp-debug`. - updated the scripts as a workaround to a known yarn issue on windows (yarnpkg/yarn#4564) Signed-off-by: vince-fugnitto <[email protected]>
Issue still exists in 1.22 |
Can confirm that still happens on version 2.4.0 :c |
Seeing this as well inside a Yarn Workspace. error C:\Users\hi\Documents\...\node_modules\@myapp\app: Command failed.
Exit code: 1
Command: electron-builder install-app-deps
Arguments:
Directory: C:\Users\hi\Documents\...\node_modules\@myapp\app
Output:
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'C:\Users\hi\Documents\...\node_modules\node_modules\electron-builder\out\cli\cli.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 { |
why this critical issue is not been solved, and even not a single contributor commented on this??? |
Not a solution, but in some cases another workaround could be to prevent yarn from hoisting the required dependencies: I.e., in the failing packages (not in the root package.json!): "workspaces": {
"nohoist": [
"rimraf"
]
} This will make sure that rimraf is resolved in the package-local node_modules. But I would appreciate a fix in yarn, too :-) |
I'm running into this as well and tried the |
Just ran into this with a co-worker on windows. |
Also running into this. 1.22.5 |
Still a problem in 2023 ... |
just ran into this issue on windows as well |
Is there a fix for this? Having the same issue |
Still the same problem in 2024... |
Quick update on what's happening here. The failure is happening when running the generated cmd files. DetailHere's an example: Say we have
Now assume our packages are scoped as:
When it gets run from the symlink path (eg. For example, this is what the paths would look like:
Why it HappensThe issue is due to the fact that yarn is adding the symlink path instead of the real path to the PATH env. @labriola was correct in it originating here: yarn/src/util/execute-lifecycle-script.js Line 198 in 7cafa51
This gets added as the top-most search location. Using the symlink path instead of the fully resolved real path will cause the relative paths to be broken. SolutionsSolution 1 : Modify execute-lifecycle-script.jsThis would be the most ideal IMO, assuming there are no side-effects. A simple change is to edit
Solution 2 : Modify cmd filesWe can resolve symlinks in the generated command files. Here is an example:
We'd want to ensure that this works with Win XP and up, but I believe it will. If not, we can also do something more simple, like using cd to the path. Questions for the Yarn TeamQuestions I'd have for the Yarn team are:
Also: I see that some patches are being accepted for Yarn 1 which are not strictly security related. Notably, I tried this on Yarn 3 and had the same issue. I'd love to get this merged, and if you require, I'll do an update Yarn 3 as well on whatever route we determine. PR |
…ipt execution (fixes yarnpkg#4564)
PR is submitted. Hopefully I can get in touch with a team member so we can get it through. Here's a release you all can use for now: I'll keep the Looks like it's working here. Would love to hear feedback if you try it out. |
…ipt execution (fixes yarnpkg#4564)
Workaround & UpdateI'm holding on completing the PR for now to see if I get a response. My published version works in the case of lifecycle scripts, but there are certain other issues where it plays a factor. It may make more sense to hit this in the generated In the mean time, I made an npx tool we can use that will correct the .cmd files by making them resolve and use the realpath, where possible / necessary. |
What is the current behavior?
When you install the main project, it correctly begins installing the workspace dependencies. However, if one of the scripts in a dependency attempts to execute a command, the location of the node_modules folder is incorrectly resolved.
As an example of the error:
\workspaceModuleBug*node_modules\node_modules*\shx\lib\cli.js
If the current behavior is a bug, please provide the steps to reproduce.
With yarn workspaces enabled, clone the following repository and do a yarn install.
https://github.com/labriola/workspaceModuleBug
Yarn will throw an error when attempting to do an shx echo.
What is the expected behavior?
The node_module path should recurse upward correctly instead of making (what I believe to be) an invalid assumption.
Please mention your node.js, yarn and operating system version.
node v.6.11.3
yarn 1.1.0
windows 10
Happy to attempt to resolve if I can get a hint on where to poke around.
The text was updated successfully, but these errors were encountered: