Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use exact version numbers in package.json or not?

Tags:

node.js

npm

Common practice for version numbers of npm dependencies in package.json has been to enter exact version numbers (like 1.2.4) instead of inexact version numbers (like ^1.2.4 which allows installing bug fix releases like 1.2.5) to make sure a future installation will not break due to changes in dependencies (see for example this article).

Using exact version numbers has a drawback in that you can't automatically update bug fix versions of dependencies. This is an issue when it's nested dependencies having security fixes or bug fixes. For example, at this moment the package karma-browserstack-launcher uses browserstack, which is using an outdated version of https-proxy-agent containing a security vulnerability. This becomes very visible right now thanks to npm audit which looks for security issues in dependencies.

Since some time we have package-lock.json, which is used to lock down the version numbers of all dependencies. This may change the way we deal exact or inexact version numbers in package.json.

My question is: given package.json and package-lock.json, what is the best strategy nowadays to deal with version numbers of dependencies? Use exact versions or not? How can I deal with security issues in nested dependencies if they don't get upgraded?

like image 585
Jos de Jong Avatar asked Jul 07 '18 12:07

Jos de Jong


People also ask

Is version required in package json?

Required name and version fields A package. json file must contain "name" and "version" fields. The "name" field contains your package's name, and must be lowercase and one word, and may contain hyphens and underscores.

Should I use latest in package json?

@thefourtheye: You generally shouldn't leave * in package. json since you might end up automatically installing a new module version with breaking changes that break your app. Since we're using --save here, the * is replaced with each package's current version.

Should package lock json be version controlled?

The package-lock. json file should always be part of your source control. Never put it into . gitignore.


1 Answers

My feeling is that

  • packages that are libraries and meant to be used to others should have inexact version numbers and should specify the minimum they require in order to work; and
  • top-level projects that aren't going to be included elsewhere should specify the full version numbers of their requirements, so they can have the most control over when things are updated.
like image 72
Sam Wilson Avatar answered Nov 14 '22 23:11

Sam Wilson