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.

npm install-ing Wagtail creates undesired changes in package-lock.json

See original GitHub issue

Initially reported by @gasman in https://github.com/wagtail/wagtail/pull/3773#issuecomment-325625388.

Issue Summary

On a fresh npm install, npm updates the package-lock.json file depending on the context the command is ran in. Those changes to the lockfile reflect which packages were installed, which can differ because of:

  1. A difference in package versions available, if the package.json uses ranges (https://github.com/npm/npm/issues/16866, https://github.com/npm/npm/issues/17979, https://github.com/npm/npm/issues/18103).
  2. A difference in the install environment (eg. installing on a different OS than the one the lockfile was created in). This is https://github.com/npm/npm/issues/17722, https://github.com/npm/npm/issues/18135.

In practice, this is problematic because it creates unnecessary file changes to deal with.

Steps to Reproduce

  1. Run npm install on an Linux machine, with the current OSX-generated package lock.

Technical details

  • npm >= 5.1.0

The first problem can be resolved once and for all by dropping all range specifiers from the package.json (^, ~), I don’t know of any “once and for all” solution for the environment difference.

The environment difference shouldn’t be more than an annoyance, however the dependency version problem can cause real issues if a new version of one of the dependencies breaks the code/tooling (using a lockfile is supposed to prevent this), so we may want to pin all of the dependencies to exact versions until it is resolved.

Until we find a more proper fix, it is safe to either:

# Discard the changes to the file:
git checkout -- package-lock.json

# Use the following flag to prevent the changes to the file:
npm install --no-shrinkwrap

I’ve been tracking all of the npm issues highlighted above, hoping for a fix in npm, if that doesn’t come I guess we can go for a plan B solution like “switch to yarn”, or “move back to npm-shrinkwrap.json and gitignore the package-lock.json”.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
thibaudcolascommented, Nov 29, 2017

According to http://blog.npmjs.org/post/167963735925/v560-2017-11-27, this has been fixed in the latest release. I’ll wait a few more days before upgrading (😉), and follow up here.

0reactions
thibaudcolascommented, Jan 17, 2018

@jjanssen regenerated the package-lock in #3806, taking care of the remaining differences.

For people who have experienced this, please make sure you use npm@5.6.0 or up:

# Version
npm --version
# Upgrade
npm i -g npm
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does "npm install" rewrite package-lock.json?
What's strange is that it actually ends up modifying and rewriting my package-lock.
Read more >
package-lock.json - npm Docs
Facilitate greater visibility of tree changes through readable source control diffs. Optimize the installation process by allowing npm to skip repeated metadata ...
Read more >
npm-package-locks - An explanation of npm lockfiles
json. The presence of a package lock changes the installation behavior such that: 1. The module tree described by the package lock is...
Read more >
Wagtail Documentation - Read the Docs
Important: Before installing Wagtail, it is necessary to install the ... The page template now needs to be updated to reflect the changes...
Read more >
Do I really need package-lock.json file? | by Shani Dar - Medium
npm install. The command npm instal installs all packages defined in package.json file and their dependencies, in the node_modules folder, creating it ...
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