I had a look into this issue. The answer is cli doesn’t support it. If your filesystem supports symlink, you can try
ln -s ../node_modules node_modules.
cli doesn’t resolve npm package path like nodejs does. It currently only looks into local node_modules folder. But nodejs does much more. nodejs tries local node_modules folder, then repeatedly tries all parent directories’ node_modules folder, if it cannot resolve a package locally. Aftercall, nodejs also tries global paths defined by NODE_PATH, and global nodejs packages (it looks like doesn’t try global npm installed packages).
UPDATE: cli actually has some code to try parents’ node_modules folder, but it doesn’t work like nodejs as cli doesn’t test whether
node_modules/packageName exists. cli only tests whether
node_modules exists, it unfortunately tries to use the blank local
node_modules folder created by yarn workspaces.
Your use case is the parent directory’s node_modules folder.
Luckily nodejs provided an api to return a resolved path of a package
I will try to make a PR to fix cli’s package resolving code using that api, instead of hard coded
'node_modules' search. This should not only improve compatibility, but also simplify cli code as it currently checks file existence manually.