I cloned a repository from github which has a package-lock.json (but no package.json). Then in a git bash terminal I go to the directory and run npm install
but I just get a message saying there is no package.json and then everything in package-lock.json gets deleted so it's basically empty except for the project name and version.
I thought running npm install
with a package-lock.json in the directory was enough to re-create node_modules, but am I seriously misunderstanding how this works? By the way I have node 8.12.0 and npm 6.4.1 and am running on Windows 10. Also, I think the package-lock.json was created on a unix system so could there be problems when using package-lock.json on a different OS?
I already tried running npm init
just to get a package.json file and then running npm install
but that still didn't get me a node_modules folder.
Starting from Mar 5, 2018, you can run npm ci
to install packages from package-lock.json.
npm ci bypasses a package’s package.json to install modules from a package’s lockfile.
https://blog.npmjs.org/post/171556855892/introducing-npm-ci-for-faster-more-reliable
package-lock.json
records the exact version and url of packages need to install, thus you can use npm to install them accordingly:
--no-package-lock
option to tell npm to not touch package-lock.json
fileFor example, to install all packages in package-lock.json
:
cat package-lock.json | jq '.dependencies[].resolved' | xargs npm i --no-package-lock
jq
is a command line tool to pares jq
, you can write a simple JavaScript script to parse it instead (if you do not want to install jq
or learn jq's query syntax).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With