Why must I run "npm install" twice for my package to install successfully

Viewed 2010

The first time I "npm install" package_1, I get the following error.

npm ERR! path C:\Users\john_\Documents\GitHub\why_npm_nesting_fails\package_1\node_modules\.staging\bignumber.js-55edd243

I don't use "bignumber" so assume it's a MySQL dependency. The second time I "npm install" package_1, it passes.

added 2 packages and audited 30 packages in 0.722s

It has something to do with MySQL since after deleting this dependency everything works the first time.

Here is a diagram of the dependencies:

enter image description here

The stripped-down project can be found at https://github.com/johngrabner/why_npm_nesting_fails Only 4 package.json files with 7 lines each, including { } demonstrates this problem. ie: 4 files with 1 line each that demonstrates this issue.

This problem is stopping me from cleanly placing my project into docker containers since the first "npm install" fails. A workaround of installing "package_4", then installing "package_3" and so on, works but I fear I am not understanding something that will come back and bite me.

The above issue occurs on both Windows and Docker Node:9.4.

1 Answers

You should definitely always keep your package-lock.json.

Here is a good description of that file and why it's so useful: package-lock.json -- A manifestation of the manifest

The important points are:

  • Describe a single representation of a dependency tree such that teammates, deployments, and continuous integration are guaranteed to install exactly the same dependencies

and

  • Optimize the installation process by allowing npm to skip repeated metadata resolutions for previously-installed packages

By deleting this file you will (kinda) confuse NPM.

It's easier to keep the package-lock.json file, then to deal with all the issues that will appear if you don't :)


package-lock.json

"This file is intended to be committed into source repositories"

(https://docs.npmjs.com/files/package-lock.json)

Related