-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Consider calling yarn and pnpm with corepack #3867
Description
- I'd be willing to implement this feature (contributing guide)
Description
Some users may not have "installed" yarn or pnpm by running corepack enable, so when Lerna runs scripts using one of those, they get an error that yarn or pnpm can't be found.
> NX Command failed: yarn --version
There's this error higher up above it:
Error: Cannot find module 'D:\src\lume+lume\node_modules\yarn\bin\yarn.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
at Module._load (node:internal/modules/cjs/loader:901:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47 {
If the project has Yarn configured, then this works when running it manually:
PS D:\src\lume+lume> corepack yarn --version
3.6.4
The corepack executable ships with Node.js, and corepack yarn and corepack pnpm work out of the box, and I bet this would work consistently and avoid the above issue (I'm not exactly sure what's the problem).
As for yarn, installing it as a local dev dependency doesn't work, due to Yarn relying on codepack, with the version on in the npm registry being old.
Not sure about pnpm, but if the latest is in the npm registry, then a library author could make it a dev dependency that would work fine.
Motivation
This is beneficial because things would just work for new contributors of a project.
As an example, I have scripts in package.json for getting started with a monorepo project, f.e. by running npm run link which uses corepack yarn install to bootstrap all packages. But subsequent Lerna commands fail.
I could tell people to run corepack enable. I could also try to automate that, but it could interfere with someone else's flow (EDIT: requires sudo or admin, so not very easy in Windows).
Suggested Implementation
Replacing yarn with corepack yarn, same with pnpm, should do the trick I think. corepack * automatically picks up and uses the project-configured package manager version from package.json, which in some ways is similar to a local install.