React-native: Ambiguous resolution of react-native

Created on 4 Sep 2017  Β·  27Comments  Β·  Source: facebook/react-native

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

  1. react-native -v: 2.0.1
  2. node -v: v8.4.0
  3. npm -v: 5.3.0
  4. yarn --version:

Then, specify:

  • Target Platform: Android

  • Development Operating System: Windows 10 Home

  • Build tools: Android Studio

Steps to Reproduce

(Write your steps here:)

  1. Rename node_modules directory to node_modules_.
  2. Delete android directory.
  3. Execute npm i
  4. Execute react-native upgrade
  5. Execute react-native run-android

After not working I even deleted the node_modules_ directory. But the problem still persists.

Expected Behavior

It should just work as expected, run the app in the Android emulator.

Actual Behavior

It's not working. React packager is complaining.

Reproducible Demo

https://github.com/ManvendraSK/ChatNowReactNativeSampleApp

packager
command
emulator

Ran Commands Locked

Most helpful comment

@ManvendraSK npm start -- --reset-cache saved the day for me:
https://github.com/facebook/react-native/issues/1924#issuecomment-249861004

All 27 comments

I have recreated the emulator after deleting it. I tried a new app and existing apps, they all are working fine.

What's the point of having two node_modules folders?

Obviously nothing. See I renamed it to node_modules_ (with extra underscore). But later I deleted it after the problem arose. But still, it is complaining to resolve from this underscored directory too! How can it be?

Moreover, we can't have two folders with the same name on Windows.

Have you tried cleaning cache? Still, I can't see any point in doing this.

I'm having the same problem.
It's pointing to package.json files in directories that no longer exists.
Have tried npm cache clean yarn cache clean etc...
Keeps trying to resolve the react_native module to the non-existent dirs.

Yes, I had tried deleting android, ios, build and node_modules directories. Then npm i followed by react-native upgrade that generates ios and android directories. Then react-native run-android and this problem occurs again.

I know no point in doing this, but all I wanted to reinstall node_modules but I didn't want the time consumed in deleting existing node_modules folder, so I just renamed it to node_modules_ folder.

Now could you please help?

Maybe clean watchman cache then? If not, unfortunately, I have no clue about this.

Ohk, I'll try cleaning watchman cache. How to do it? Command? Directory? I'll keep you posted here. Thanks.

@ManvendraSK try watchman watch-del-all
Unfortunately, it did not help me 😞

@jonathanoron I'll try when back at home, right now in office ;-).

Let's see what is next, I'll keep you posted here. May be somebody would help like Batman! :-P

@ManvendraSK npm start -- --reset-cache saved the day for me:
https://github.com/facebook/react-native/issues/1924#issuecomment-249861004

Thanks @jonathanoron. I'll try it when at home. :+1:

Hey @jonathanoron and @radko93, it's working fine!

npm start -- --reset-cache does work! But, after it has executed we need to kill this command and start with the usual one react-native run-android. watchman didn't work though!

Thanks, guys. You both are Batman for me!

@facebook-github-bot answered

Closing this issue as @radko93 says the question asked has been answered.

In my case, It seems that I had conflicts between .yarn directory and node_modules, despite I did a clean yarn install.

Deleting .yarn and starting the app with npm start solved this problem for me, but it doesn't feel like the correct solution.

i tried to install,
npm install --save [email protected]
npm install -g react-native-git-upgrade
react-native-git-upgrade

fixed thanks folks

Reboot mac works

Also, delete system32

having this same issue, I am on mac, restarting doesn't work, neither refreshing node_modules and clearing cache..

using :
"react": "16.0.0",
"react-native": "0.50.1",

Is there anything else I can try

simulator screen shot - iphone 6 - 2018-01-09 at 03 34 47

For those of you trying to create a library/bridge:

I just got this error, and it was because I had put an example app inside my library:

.
β”œβ”€β”€ README.md
β”œβ”€β”€ android
β”‚Β Β  β”œβ”€β”€ build.gradle
β”‚Β Β  └── src
β”œβ”€β”€ example
β”‚Β Β  β”œβ”€β”€ App.js
β”‚Β Β  β”œβ”€β”€ __tests__
β”‚Β Β  β”œβ”€β”€ android
β”‚Β Β  β”œβ”€β”€ app.json
β”‚Β Β  β”œβ”€β”€ index.js
β”‚Β Β  β”œβ”€β”€ ios
β”‚Β Β  β”œβ”€β”€ node_modules
β”‚Β Β  β”œβ”€β”€ package.json
β”‚Β Β  └── yarn.lock
β”œβ”€β”€ index.js
β”œβ”€β”€ ios
β”‚Β Β  └── app.xcodeproj
β”œβ”€β”€ node_modules
β”œβ”€β”€ package.json
└── yarn.lock

Which means that when I ran react-native run-android, my index.js would find react-native in ./example/node_modules, but also in ./example/node_modules/MyApp/example/node_modules/....

The fix was to add a ./.npmignore file with example/* which prevents this recursion from happening, and make sure that ./package.json didn't have react-native in its dependencies (peerDependencies is okay).

I then did:

  • cancel any yarn/npm/react-native processes (those that are started from run-android)
  • delete node_modules in both ./ and ./example/
  • yarn in both ./ and ./example/
  • yarn start --reset-cache from ./example/

Edit: Finally noticed that my issue is related to a yarn issue. They don't seem to have a fix besides downgrading to 0.26.1 (which introduced another bug for me), so will have to do with the above for now.

For me the error appeared in calling my Project ReactNative!
As soon as I changed the name to something different than ./ReactNative the error disappeared!

Any idea when this will be solved? For now I cannot install any pods that install React as well.

If nothing helps remove duplicate dependencies from Pods & react native links. Then clear Pods cache & reinstall them using this : gist
then do above stuff. Spent half day on this

Generally this issue arises when there are two folders of react-native. More often, if you use Pods, you have dependency that relies on the 'React' pod and thus you should reference the pod in your node_modules/ not install anothe react-native from cocopods. To do so, you can add the following to your Podfile

  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
  pod 'React', :path => '../node_modules/react-native'

Full reset that worked for me:

#!/bin/bash
echo "Completely resetting life"
echo "STARTING: Deleting Node modules"
rm -rf ./node_modules
echo "FINISHED: Deleting Node modules"
echo "STARTING: Removing yarn.lock file"
rm yarn.lock
echo "FINISHED: Removing yarn.lock file"
echo "STARTING: Deleting Watchman and yarn cache"
watchman watch-del-all
yarn cache clean
echo "STARTING: Re-installing node modules"
yarn install
echo "FINISHED: Re-installing node modules"
echo "STARTING: restarting app"
yarn start --reset-cache

npm start -- --reset-cache solved the problem for me. thx!!!

Was this page helpful?
0 / 5 - 0 ratings