Home > Enterprise >  React Native: when I run `npm i`, some dependencies in package-lock.json are different from package.
React Native: when I run `npm i`, some dependencies in package-lock.json are different from package.

Time:09-10

In my React Native project, I have a specific version of a library, specifically [email protected], that I need to use in the project. When I run npm i [email protected], everything works fine, but if I re-build the project with npm i, even though package.json has [email protected], in package-lock.json, it gets resolved to [email protected].

What I Want To Know:

a) Why would the actual version get resolved to 1.2.1 instead of 1.1.1?

b) Is there a way to enforce that npm i will install 1.1.1 instead of 1.2.1?

CodePudding user response:

That is because when you npm install a specific package, say npm i [email protected], it gets resolved with a caret before it in Package.json, so in your package.json it will be written like this

"permission": "^1.1.1"

Which means “Compatible with version”, will update you to all future minor/patch versions, without incrementing the major version. ^2.3.4 will use releases from 2.3.4 to <3.0.0.

If you want to keep the specific package only during installs, then remove the caret before the version. or use "--save --save-exact" flag during npm install

  • Related