lerna / lerna/lerna

Consider calling yarn and pnpm with corepack

Open
#3,867 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: feature
Dominant language
TypeScript
Stars
36.1k
Forks
2.3k
Avg merge
1d 4h
Merged PRs (30d)
50

Description

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.

Alternate Implementations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the contributing guide and the package.json scripts described in the issue, then trace where Lerna invokes Yarn and pnpm. Verify the behavior with a project-configured package manager, and consider the work done when those commands run through Corepack without requiring contributors to enable it manually.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js
Domain
build-system
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.