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.
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
to - ..\workspaceModuleBug\node_modules\[package]\dist\index.js
..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:
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, node_modules twice and scripts in node_modules/.bin cannot be executed.
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?
error C:\Users\pronebird\mullvad\mullvadvpn-app\gui\node_modules\@mullvad\components: Command failed.
Exit code: 1
Command: yarn run build
Arguments:
Directory: C:\Users\pronebird\mullvad\mullvadvpn-app\gui\node_modules\@mullvad\components
Output:
yarn run v1.9.4
$ run-s private:build:clean private:build:compile
module.js:549
throw err;
^
Error: Cannot find module 'C:\Users\pronebird\mullvad\mullvadvpn-app\gui\node_modules\node_modules\npm-run-all\bin\run-s\index.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
I was able to fix this by adding a preinstall script to one of workspace packages that linked node_modules\node_modules to node_modules. Ugly but it works. I wonder why this is not being addressed for almost a year. Seems like a critical bug.
I was able to fix this by adding a preinstall script that linked node_modules\node_modules to node_modules to one of packages in workspace. Ugly but it works. I wonder why this is not being addressed for almost a year. Seems like a critical bug.
I'm facing same issue.
Issue still exists in 1.22
Most helpful comment
Issue still exists in 1.22