Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "requires: true" do in package-lock.json

Our team just updated to npm@5. The package-lock.json was unified between Windows and Mac (certain dependencies are optional so they don't get installed on Windows, but they do on Mac) so that no matter the machine, we'd generate the same node_modules structure. That went fine, then each of the team members went through the following steps:

  1. rm -rf node_modules
  2. git pull
  3. npm install

This actually went perfectly for all team members except for one, who had a modified package-lock.json after the npm install. The one modified line was that it removed "requires": true.

So I saw:

{
  ...
  "version": "0.0.1",
  "lockfileVersion": 1,
  "requires": true,
  "dependencies": {
  ...
}

But he saw:

{
  ...
  "version": "0.0.1",
  "lockfileVersion": 1,
  "dependencies": {
  ...
}

Does anybody know why requires: true might be removed from the package-lock.json file on some machines but not others? Also, a little explanation of what this property does wouldn't hurt. :)

Thanks in advance!

like image 385
atdrago Avatar asked Jul 15 '17 11:07

atdrago


People also ask

What is optional true in package-lock json?

After a package is removed from dependencies, its dependencies are marked "optional": true in package-lock. json . It is usually safe to remove such packages either by hand or by $ rm -rf package-lock. json node_modules/ $ npm install. However, this is not 100% safe, as some packages will be updated to newer versions.

What is true package json?

package. json is present in the root directory of any Node application/module and is used to define the properties of a package. It can also be used to update dependencies of a Node application.

What does Dev true mean in package-lock?

So answering your first question, "dev": true in package-lock. json means this dependency won't be installed by npm install / npm ci when running in production mode.

Is package-lock json required?

If you're collaborating on a shared project with multiple developers, and you want to ensures that installations remain identical for all developers and environments, you need to use package-lock. json . package-lock. json is automatically generated for any operations where npm modifies either package.


1 Answers

As I suspected in my comments, the requires field has been added since 5.1.0. You can see the related pull request here https://github.com/npm/npm/pull/17508 (changelog visible here https://github.com/npm/npm/releases/tag/v5.1.0)

To quote what it says:

This has a handful of fixes:

  1. It introduces a new package-lock.json field, called requires, which tracks which modules a given module requires.
  2. .....

To avoid these kind of conflict, I advise you (and myself as well) to ensure all your team mate are using the same npm version.

UPDATE

After upgrading npm to version 5.1.0, I was having trouble with missing dependencies (working on an Angular 4 application). If anyone is experiencing the same issue, here is what I did to solve it:

rm -rf node_modules
npm prune
npm install

Hope it helps.

like image 91
lkartono Avatar answered Sep 28 '22 00:09

lkartono