wonday / react-native-orientation-locker

A react-native module that can listen on orientation changing of device, get current orientation, lock to preferred orientation.
MIT License
752 stars 272 forks source link

Support for react 17 #196

Open bandtank opened 3 years ago

bandtank commented 3 years ago

I am brand new to react, react-native, and mobile programming, so please be gentle. I have been searching for hours to try to understand how to resolve this issue:

npm ERR! While resolving: annotator@0.0.1
npm ERR! Found: react@17.0.1
npm ERR! node_modules/react
npm ERR!   react@"17.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"16.13.1" from react-native-orientation-locker@1.3.1
npm ERR! node_modules/react-native-orientation-locker
npm ERR!   react-native-orientation-locker@"^1.3.1" from the root project

I understand what it means, but I'm confused because the code I'm using was given to me by a person who demonstrated its use right in front of me. I don't understand how that's possible if I am unable to install the dependencies for the project. Regardless, I know the react-native-orientation-locker module wants an older version of react than package.json specifies, but I don't know what to do about it.

I believe my options are to remove the module, which will break the app, or replace it, which would require modifying the code and I'm not ready to do that yet. Am I missing a third option? I doubt I am, but I thought I'd check to be sure. Additionally, presuming I have to make a breaking change if i want to use version 17, is there a plan for the module to support version 17 in the near future?

bandtank commented 3 years ago

Ok, so, I just realized the creator of the code specified yarn install instead of npm install. After running the former, the project installed as expected. However, the following warnings were issued:

warning "react-native > react-native-codegen > jscodeshift@0.11.0" has unmet peer dependency "@babel/preset-env@^7.1.6".
warning " > react-native-orientation-locker@1.3.1" has incorrect peer dependency "react@16.13.1".
warning " > react-native-orientation-locker@1.3.1" has incorrect peer dependency "react-native@0.63.2".
warning " > react-native-orientation-locker@1.3.1" has unmet peer dependency "react-native-windows@^0.63.3".

Is it safe to ignore these warnings? Also, why did yarn install the dependencies even though npm could not?

slaci commented 3 years ago

Peer dependencies for this package are extremely strict (for no reason I think) and npm takes those rules more seriously than yarn. There is a pull request which would fix it.

The error could be ignored by `npm install -f``, but of course you have to test if the package still works with your versions (it should, because react 17 was a very light release).

wilson208 commented 3 years ago

for anyone else running into this, until #190 is merged, temporary workaround is to set the following npm config

Globally: npm config set legacy-peer-deps true

Or set this in a .npmrc for your specific project: echo "legacy-peer-deps=true" >> /path-to-your-project/.npmrc