Question
Is it a way to update/generate package-lock.json
without making real install of node_modules
(like npm i
)? I just need a valid package-lock.json
based on my package.json
, that's it.
Motivation
You (or your colleagues) might use yarn
locally, when CI server uses npm
. It's probably not a best practice, but still might be for some reasons.
In a perfect world I'd like to have a command to update package-lock.json
Bonus question: Same for yarn
. Is there a way to generate yarn-lock.json
without modules install (yarn install
)?
package-lock. json : this file is generated by npm install. If npm install ends up upgrading packages, it will output a new package-lock. json which contains details about the newer versions of the packages that were installed.
The package-lock. json file needs to be committed to your Git repository, so it can be fetched by other people, if the project is public or you have collaborators, or if you use Git as a source for deployments. The dependencies versions will be updated in the package-lock. json file when you run npm update .
Using a locked package is no different than using any package without a package lock: any commands that update node_modules and/or package. json 's dependencies will automatically sync the existing lockfile. This includes npm install , npm rm , npm update , etc.
The `package-lock. json` file was introduced in npm version 5 to solve this problem. It is a generated file and is not designed to be manually edited.
As of npm 6.x, you can use the following command:
npm i --package-lock-only
Documentation (https://docs.npmjs.com/cli/install.html) says:
The --package-lock-only argument will only update the package-lock.json, instead of checking node_modules and downloading dependencies.
As of Sep. 10, 2019: yarn doesn't seem to support generating a lock-file without installing the modules. Relevant GitHub issue: https://github.com/yarnpkg/yarn/issues/5738
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