Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to run react-native link on my project

Tags:

react-native

When I run react-native link on my RN project, I got below error:

$ react-native link
rnpm-install ERR! ERRPACKAGEJSON No package found. Are you sure it's a React Native project?

Cannot read property '_text' of undefined

I have searched that some people say run react-native upgrade will resolve this issue. I have tried but no lock. My react version is shown as below:

$ react-native --version
react-native-cli: 2.0.1
react-native: 0.39.2

How can I solve this issue?

like image 385
Joey Yi Zhao Avatar asked Dec 07 '22 18:12

Joey Yi Zhao


2 Answers

Follow below steps in order -

  1. npm cache clean or yarn cache clean
  2. rm -rf node_modules
  3. yarn install or npm install
  4. react-native upgrade ( You can choose no in all steps)
  5. react-native link

If you get permission related error use sudo with all commands.

like image 176
WitVault Avatar answered Dec 11 '22 09:12

WitVault


A little late but this may help someone else. My problem was large commented out copies of <manifest> ... </manifest> in android/app/src/main/AndroidManifest.xml. Once I removed commented out copies, link worked as expected.

It seems xmldoc had touble parsing the manifest even though the AndroidManifest.xml was valid XML. Calling react-native link uses ../node_modules/react-native/local-cli/core/android/index.js. To debug such issues in future I would start with putting debugging statements in ../node_modules/react-native/local-cli/core/android/index.js and narrow down to the root cause of the issue. Similar logic should work for ios.

like image 45
Kahitarich Avatar answered Dec 11 '22 08:12

Kahitarich