问题
If two different developers are using different versions of node (12/15) & npm (6/7) in a project that was originally created using a package-lock.json
"lockfileVersion": 1
, when the developer using npm 7x installs new packages it seems that the package-lock.json
is re-created using "lockfileVersion": 2
.
This seems to cause issues for the developer using npm v6, as it tries to work with the lockfileVersion 2
, but it ends up producing new diffs.
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
Is there any way to specify to newer versions of npm
to only use "lockfileVersion": 1
? Or do we just have to get all devs on the same version of npm
?
回答1:
Is there any way to specify to newer versions of
npm
to only use"lockfileVersion": 1
? Or do we just have to get all devs on the same version ofnpm
?
i will advise you to pin node\npm version and align it across your environments (development, staging, and production).
you can leverage nvm for managing the node version by adding to your project .nvmrc file (don't forget to store it in your source control).
for instance, .nvmrc
will look like:
$ cat .nvmrc
14.15.0
then, you can use nvm install && nvm use
to use the pined version of node.
npm also supports engines:
You can specify the version of node that your stuff works on:
{ "engines" : { "node" : ">=0.10.3 <0.12" } }
And, like with dependencies, if you don't specify the version (or if you specify "*" as the version), then any version of node will do.
If you specify an "engines" field, then npm will require that "node" be somewhere on that list. If "engines" is omitted, then npm will just assume that it works on node.
You can also use the "engines" field to specify which versions of npm are capable of properly installing your program. For example:
{ "engines" : { "npm" : "~1.0.20" } }
Unless the user has set the engine-strict config flag, this field is advisory only and will only produce warnings when your package is installed as a dependency.
来源:https://stackoverflow.com/questions/64813775/is-there-any-way-to-fix-package-lock-json-lockfileversion-so-npm-uses-a-specific