react-native-svg: Ambiguous resolution

Hello,

after upgrading react-native to the latest RC, bundling fails together with react-native-svg:

Bundling `index.android.js`  [development, non-minified, hmr disabled]  0.0% (0/1), failed.
error: bundling failed: ambiguous resolution: module `/Users/so/Documents/workspace/my-app/index.android.js` tries to require `react-native`, but there are several files providing this module. You can delete or fix them:

  * `/Users/so/Documents/workspace/my-app/node_modules/react-native-svg/node_modules/react-native/package.json`
  * `/Users/so/Documents/workspace/my-app/node_modules/react-native/package.json`

Versions:

react-native-cli: 1.0.0
react-native: 0.48.4
react-native-svg: 6.0.0-rc1

Any idea?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 21
  • Comments: 25

Most upvoted comments

Try yarn start --reset-cache

Just a small correction: to pass --reset-cache via yarn, you need to pass the a separator first, otherwise node will be called without the argument.

yarn start -- --reset-cache
...
node node_modules/react-native/local-cli/cli.js start --reset-cache

@RuiDamiao ,restart your mac will resolve this problem.Works for me.

I fixed it by adding below lines to the pod file, to make sure CocoaPod gets React dependency from node_modules instead of creating a new directory and pulling from other repo.

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

@perzect I’ve already tried. The problem is that this path ‘D:\PORTAL.MOBILE\PortalMobile\node_modules\react-native-view-more-text\node_modules\react-native\package.json’ doesn’t exist. I don’t know what to do. I cloned the project again and the first time worked well, I’ve installed another module and I got this error again and now even when I clone the project (again) I get this error right away…

UPDATE If anybody has a similiar problem i solved my with this

  • npm uninstall {module name}
  • rmdir /s /q node_modules -npm install -npm start – --reset-cache (the error disappeared and the module was missing)
  • npm install {module name} (everything is fine now)

@endel That’s no longer necessary in the latest version of yarn.

I fixed this by removing all Pod stuff and reinstall them

I had the same problem. Any solution did not help but cloning project in new folder solve this.

there are two different versions of react-native in your package.json files.

I’ve restarted my Mac, and I have tried with yarn start -- --reset-cache. Any other idea? This hapened when I added Podfile and started using Pods.

@allanjsx 's solution worked for me, except I also had to delete the existing React pod in the ios dir.

Strange that React Native will let this problem occur by default. Lots of packages end up creating a duplicate React pod if you don’t force it to use the one from node_modules; I encountered it with the react-native-camera package.

@RuiDamiao Yep! Delete node_modules will not resolve this Pro. Maybe the key is 'npm uninstall '.I’ll try this next time.

I had to delete the node_module and Pods folder. and npm i and then pod update pod install .

This is because initially I started the project and in the podfile there was no React mentioned. It was working, then I added another library ( fast-image) and that needed the React to be inside the podfile and then after that it got confused.

Similar to @xe4me solution, this worked for me:

rm -rf node_modules && yarn
pod deintegrate
pod install

Most likely you have react native being provided as a variable from the ios pods/React/package.json file, as well as from the base package.json file. Please confirm if this is the case.