[rush] Enable support for "pnpm link" for testing changes to an external project
Summary
Hello, I made (making) a node library that is stored inside a rush monorepo. I can link to this library fine from sibling projects (in the same monorepo) But I am having problems when trying to use pnpm link to my library from a project outside the rush monorepo. Is there guidence on how to do this?
In my circumstance, xlib is the library project. I called pnpm link from it's project folder and that looks to have completed fine.
Here is the error I get when I try to link from the external project:
19:44:55 ❯ pnpm link xlib
ERROR In ../../root/.nvm/versions/node/v14.15.0/pnpm-global/node_modules/xlib: No matching version found for @xlib/build-tools@* inside the workspace
The @xlib/build-tools@* referenced in the error is a devDependencies helper lib in the rush monorepo
Repro steps
Expected result:
debug the dependent project with xlib node module mapped to the rush monorepo
Standard questions
Please answer these questions to help us investigate your issue more quickly:
| Question | Answer |
|---|---|
@microsoft/rush globally installed version? |
5.34.0-pr2172.0 |
rushVersion from rush.json? |
"5.35.2" |
useWorkspaces from rush.json? |
true |
| Operating system? | ubuntu 20.04 via WSL2 (win10) |
| Would you consider contributing a PR? | no |
Node.js version (node -v)? |
v14.15.0 |
the error is for workspace pages, for example in my package.json devDependencies section is: "@novaleaf/xlib-build-tools": "workspace:*", which caused the above error
here is a workaround: set "useWorkspaces": false in rush.json and make all packages registered/published on npm. then external projects can call pnpm link
I will leave this issue open in case a contributor has a 'real' solution
Sounds related to issue https://github.com/microsoft/rushstack/issues/2347
Can you share a repro repo? Following the steps that you posted (without the workaround) work for @apostolisms.
@iclanton I am not doing anything special. I am guessing, that probably @apostolisms didn't set useWorkspaces:true (the default is false) so that's why it "worked" without a workaround.
Repo is my xlib repo.
This commit implements my described workaround: https://github.com/Novaleaf/xlib/commit/0fb1ef5b8c58474519e9d554f4e0e4dc86333597 but there is still an eslint-config bug that needed to be fixed so the first buildable commit is https://github.com/Novaleaf/xlib/commit/62f21ac9102b9ec7575959310cce73d52d7efdda
the best commit to see the problem is https://github.com/Novaleaf/xlib/commit/01f4871ecc81c53ca54598c5d18f55ce6373409b
I'm pretty sure this is the exact same problem as https://github.com/microsoft/rushstack/issues/2347
I faced the same problem here and to solve that I created this workaround. I mapped these packages directly to "tar.zg" files and install only these libraries with pnpm and the process is something like this...
First, they should be neighbors:
|--- monorepo
|--- package-one
|--- package-two
|--- external-project
Mapping these libraries in the external-project package.json like that:
"dependencies": {
"@SCOPE_NAME_HERE/package-one": "../monorepo-folder/common/temp/artifacts/packages/package-one-1.0.0.tgz",
"@SCOPE_NAME_HERE/package-two": "../monorepo-folder/common/temp/artifacts/packages/package-two-1.0.0.tgz"
}
After, follow these steps:
- run
rush rebuild; rush publish --pack --include-all --publish(to make an easier run, I've created a rush script called "pack") inmonorepo; - run
rm -rf node_modules/@SCOPE_NAME_HERE; pnpm add ../monorepo-folder/common/temp/artifacts/packages/package-one-1.0.0.tgz; pnpm add ../monorepo-folder/common/temp/artifacts/packages/package-two-1.0.0.tgz(I also created an script called "lib-update") inexternal-project
Repeat these steps every time you make changes in monorepo libraries and need to test it locally. I know that It's not the best approach but it works fine while rush doesn't have a native way to do that.
This is partially solved by the new rush-pnpm command, released with @microsoft/rush 5.74.0.
However it's an imperfect solution. It would be better for Rush to provide a built-in feature to make this a good experience -- that idea is being tracked by #1719 which is still open.