React-native@0.26.3 requires a peer of react@15.0.

2019-04-24 08:09发布

I am trying to set up for the react native. but whenever I update files it gives m error

    enoent ENOENT: no such file or directory, open 'React Native/package.json'
npm WARN react-native@0.26.3 requires a peer of react@15.0.2 but none was installed.
npm WARN React Native No description
npm WARN React Native No repository field.
npm WARN React Native No README data
npm WARN React Native No license field.
   MacBook-Pro:React Native$ npm info react dist-tags.latest

Please let me know how can I fix.

4条回答
神经病院院长
2楼-- · 2019-04-24 08:44

Some steps that worked for me:

1. watchman watch-del-all
2. rm -rf node_modules
3. npm install react@15.0.2 --save
4. npm install react@15.1.0 --save
5. npm install
6. rm -fr $TMPDIR/react-*
7. npm start -- --reset-cache
查看更多
淡お忘
3楼-- · 2019-04-24 08:49

In my specific case I was running npm install in the wrong directory. I thought I was in my project directory but was one level higher. This meant react was missing from installed packages (because there were none) and thus gave this error.

查看更多
男人必须洒脱
4楼-- · 2019-04-24 08:50

Installing react should fix the error

npm install react --save

Also, you may try upgrading your react-native install. react-native is as v0.30.0 now

npm update react-native
查看更多
劫难
5楼-- · 2019-04-24 09:05

In my case, the project I am working on requires a specific version of React. Since it was older than the current release, doing an install/update would still cause the error.

In order to fix the problem, I had to check the package.json of the project and install the exact version allowed by the dependency definition. In the OP's case, a

npm install react@15.0.2

should fix the problem by installing the exact version of the React module that react-native requires.

Verify that the condition was resolved by doing a npm list to see if there are any other unmet peer dependencies.

查看更多
登录 后发表回答