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 adds package-lock.json to git

See original GitHub issue

I learned that package-lock.json is preferably ignored under packages/**, and only the package-lock.json in the root should exist. So I added packages/**/package-lock.json into .gitignore. Now when I run lerna version (or lerna publish), apparently it generates a git add command which includes these package-lock.json files as well for some reason, and it fails with a message:

lerna ERR! lerna The following paths are ignored by one of your .gitignore files: … paths to package-lock.json files…

Expected Behavior

package-lock.json files should not be explicitly added in git add command which is generated by lerna version. I would at least expect it to do git add -A, so that files ignored in .gitignore are ignored.

Current Behavior

The following git add command has been generated: git add – packages/util/package.json packages/util/package-lock.json and it fails with the above error message.

Possible Solution

Run git tag -A instead of creating a big git add file1 file2 file3 etc. command

Steps to Reproduce (for bugs)

Example: https://gitlab.com/coldevel/lerna-version-ignore-bug – see replication instructions there

lerna.json

{
  "packages": [
    "packages/*"
  ],
  "version": "independent",
  "command": {
    "version": {
      "allowBranch": "master"
    }
  }
}

lerna-debug.log

1 notice cli v3.18.4
2 verbose rootPath /Users/darko/lerna-version-ignore-bug
3 info versioning independent
4 silly isAnythingCommitted
5 verbose isAnythingCommitted 1
6 silly currentBranch
7 verbose currentBranch master
8 silly remoteBranchExists
9 silly isBehindUpstream
10 silly isBehindUpstream master is behind origin/master by 0 commit(s) and ahead by 0
11 silly hasTags
12 verbose hasTags false
13 info Assuming all packages changed
14 verbose updated util
15 verbose git-describe undefined => "7d7aa69"
16 silly git-describe parsed => {"refCount":"1","sha":"7d7aa69","isDirty":false}
17 info execute Skipping releases
18 silly lifecycle No script for "preversion" in "root", continuing
19 silly lifecycle No script for "preversion" in "util", continuing
20 silly lifecycle No script for "version" in "util", continuing
21 silly lifecycle No script for "version" in "root", continuing
22 silly gitAdd [ '/Users/darko/lerna-version-ignore-bug/packages/util/package.json',
22 silly gitAdd   '/Users/darko/lerna-version-ignore-bug/packages/util/package-lock.json' ]
23 error Error: Command failed: git add -- packages/util/package.json packages/util/package-lock.json
23 error The following paths are ignored by one of your .gitignore files:
23 error packages/util/package-lock.json
23 error Use -f if you really want to add them.
23 error
23 error     at makeError (/usr/local/lib/node_modules/node/lib/node_modules/lerna/node_modules/execa/index.js:174:9)
23 error     at Promise.all.then.arr (/usr/local/lib/node_modules/node/lib/node_modules/lerna/node_modules/execa/index.js:278:16)

Context

I constantly have to update and resolve conflicts in package-lock.json files in individual sub-projects in the Lerna monorepo, so I decided to listen to the advice of Lerna maintainers ignore / not use them. Since every run to lerna bootstrap generates these files anyway, and so does running npm install in individual projects, I have added a line to my .gitignore: packages/**/package-lock.json. Running lerna version stops working now as described above.

Your Environment

Executable Version
lerna --version 3.18.4
npm --version 6.13.0
node --version v10.16.3
OS Version
macOS Catalina 10.15.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:17
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
evocateurcommented, Dec 27, 2019

If your lerna bootstrap is creating lockfiles, you shouldn’t be ignoring them. If you’re following my guidance to avoid lockfiles in leaf packages, that means you should be using relative file: specifiers in project root package.json, allowing npm to create a lockfile for the whole project, and thus avoiding the leaf node lockfiles.

You can accomplish this by running the following commands (assuming you’re using the default packages location):

rm -rf packages/*/package-lock.json packages/*/node_modules
npx lerna link convert
npm i ./packages/*

With those commands executed, you now no longer need to run lerna bootstrap, a simple npm install in the root will suffice.

1reaction
mattstraincommented, Sep 9, 2022

Commenting in case this helps someone. I got around this in CI by simply deleting the package-lock.json file before the lerna publish cmd, which for us was the last action in the release stage anyway. This is probably only most useful in CI environments

Read more comments on GitHub >

github_iconTop Results From Across the Web

package-lock.json - infra/infra/crdx/chopsui-npm - Git at Google
"name": "chopsui",. "requires": true,. "lockfileVersion": 1,. "dependencies": {. "@babel/code-frame": {. "version": "7.0.0",.
Read more >
Version and Publish - Lerna
json with the version number, commits the change, adds a corresponding version tag (e.g. v1.0.0 ) and pushes the commit and the tag...
Read more >
npm ci can only install packages with an ... - Stack Overflow
I reset package-lock.json with the version from master , removed that npm ... add "npm i" as one of the scripts to run...
Read more >
Things I wish I had known when I started JavaScript monorepo ...
Only root level package-lock.json file is maintained. It contains information for installing the entire monorepo with all it's packages. None of ...
Read more >
package.json - npm Docs
When installing from a git repository, the presence of certain fields in the package.json will cause npm to believe it needs to perform...
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