Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update package-lock.json without doing npm install?

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)?

like image 758
Sergei Panfilov Avatar asked Sep 10 '19 08:09

Sergei Panfilov


People also ask

Does npm install update package lock json?

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.

Can you update package lock json?

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 .

Does npm install update lock file?

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.

Can I edit package lock json manually?

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.


1 Answers

npm

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.

yarn

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

like image 186
Teh Avatar answered Sep 30 '22 07:09

Teh