question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

lerna --version incorrectly updates package-lock.json generated with npm@7

See original GitHub issue

Expected Behavior

Package version should be correctly updated in package-lock.json version 2 with lerna --version command.

Current Behavior

When package-lock.json in version 2 is used (generated by npm@7) then lerna --version command updates only the first (root) version information in the package-lock.json. The information in the packages section of package-lock.json is left with an old version.

{
  "name": "@space/types",
  "version": "1.0.13",
  "lockfileVersion": 2,
  "requires": true,
  "packages": {
    "": {
      "name": "@space/types",
      "version": "1.0.11",
      "dependencies": {
        "@space/constants": "file:../constants",
        "fp-ts": "^2.9.5",
        "io-ts": "^2.2.14",
        "joi": "^17.4.0"
      }
    },
(...)

Steps to Reproduce (for bugs)

  1. Install and use npm@7
  2. Create a lerna monorepo with “version”: “independent”
  3. Add a package, publish it to have an initial version published
  4. Make some changes in the package, commit, push
  5. Run lerna --version to tag a new version
  6. Review pushed changes in package-lock.json
lerna.json

{
  "packages": [
    "packages/*"
  ],
  "version": "independent",
  "command": {
    "publish": {
      "ignoreChanges": [
        "*.md"
      ],
      "registry": "<redacted>"
    }
  }
}

Your Environment

Executable Version
lerna --version 3.22.1
npm --version 7.6.0
node --version 14.15.0
OS Version
macOS Catalina 10.15.7

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:12
  • Comments:11

github_iconTop GitHub Comments

5reactions
hudochenkovcommented, Nov 28, 2021
1reaction
tex0lcommented, Mar 18, 2021

I can reproduce the issue and I understand what’s happening, but I have no solution.

It comes from an inconsistent installation of npm. The version you have in your path differs from the one actually used by lerna in the packages.

I use npm@7.6.3 with node@14.16.0. I installed the node@14 package with Homebrew which initially comes with npm@6.14.11 but updated it with npm i -g npm --force. When I use npm from my shell:

✗ npm --version 
7.6.3

But lerna doesn’t use the same binary for npm, it uses the one intially installed with node@14

✗ lerna exec -- npm --version
lerna notice cli v3.22.1
lerna info Executing command in 5 packages: "npm --version"
6.14.11
6.14.11
6.14.11
6.14.11
6.14.11
lerna success exec Executed command in 5 packages: "npm --version"

This is confirmed by test which npm from the shell:

✗ which npm
/usr/local/bin/npm

And from lerna exec:

✗ lerna exec -- which npm    
lerna notice cli v3.22.1
lerna info Executing command in 5 packages: "which npm"
/usr/local/Cellar/node@14/14.16.0_1/bin/npm
/usr/local/Cellar/node@14/14.16.0_1/bin/npm
/usr/local/Cellar/node@14/14.16.0_1/bin/npm
/usr/local/Cellar/node@14/14.16.0_1/bin/npm
/usr/local/Cellar/node@14/14.16.0_1/bin/npm
lerna success exec Executed command in 5 packages: "which npm"

Using lerna info, this is not detected:

✗ lerna info
lerna notice cli v3.22.1

 Environment info:

  System:
    OS: macOS 11.2.3
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Binaries:
    Node: 14.16.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.6.3 - /usr/local/bin/npm
  Utilities:
    Git: 2.30.0 - /usr/local/bin/git
  npmPackages:
    lerna: ^3.22.1 => 3.22.1 

I didn’t find what $PATH lerna exec uses, nor how to configure it to use the same one as the current shell.

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm WARN old lockfile The package-lock.json file was ...
Commit the updated version of package-lock.json to the repo/Docker ... And npm@7 which is the latest release generates package-lock@v2 .
Read more >
npm-check-updates
npm -check-updates upgrades your package.json dependencies to the latest versions, ignoring specified versions.
Read more >
Things I wish I had known when I started JavaScript monorepo ...
I think the biggest problem with Lerna lies in it's documentation. ... monorepo - package.json (root package.json) - pacakge-lock.json (root ...
Read more >
Solving conflicts in package-lock.json - TkDodo's blog
npm will automatically resolve any conflicts for you and write a merged package lock that includes all the dependencies from both branches in...
Read more >
JavaScript package managers compared: npm, Yarn, or pnpm?
Install or update Yarn Classic to the latest 1.x version ... With $ npm install , or the shorter $ npm i ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found