1

In my React Native project, I have a specific version of a library, specifically react-native-permissions@1.1.1, that I need to use in the project. When I run npm i react-native-permissions@1.1.1, everything works fine, but if I re-build the project with npm i, even though package.json has react-native-permission@1.1.1, in package-lock.json, it gets resolved to react-native-permissions@1.2.1.

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?

gkeenley
  • 6,088
  • 8
  • 54
  • 129

1 Answers1

1

That is because when you npm install a specific package, say npm i permissions@1.1.1, 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

Vin Xi
  • 986
  • 2
  • 11
  • Perfect, thanks! Do you know under what circumstances ^1.1.1 would get resolved to a higher version? Is it just if another package requires it? – gkeenley Sep 09 '22 at 19:03
  • If a higher version is released and available, npm will install it – Vin Xi Sep 12 '22 at 06:29