Sometimes, we install a new library for our react-native. Suddenly, a duplicate module name error occurs.

Loading dependency graph...(node:58731) UnhandledPromiseRejectionWarning: Error: jest-haste-map: Haste module naming collision:
  Duplicate module name: react-native
.....

What???!!! Now how do we remove this error. There is a way to do it by simply editing the Podfile in the ios folder. Here are the steps to fix this problem.

Edit {project_dir}/ios/Podfile

....

target '{project name}'
....
  # Pods for your project
    rn_path = '../node_modules/react-native'

  pod 'yoga', path: "#{rn_path}/ReactCommon/yoga/yoga.podspec"
  pod 'DoubleConversion', :podspec => "#{rn_path}/third-party-podspecs/DoubleConversion.podspec"
  pod 'Folly', :podspec => "#{rn_path}/third-party-podspecs/Folly.podspec"
  pod 'glog', :podspec => "#{rn_path}/third-party-podspecs/GLog.podspec"
  pod 'React', path: rn_path, subspecs: [
    'Core',
    'CxxBridge',
    'RCTAnimation',
    'RCTActionSheet',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket',
    'RCTPushNotification',
    'RCTCameraRoll',
    'RCTBlob',
    'RCTGeolocation',
    'DevSupport'
  ]

  // Any third party library you want to use
  pod 'third-party-lib1', :path => '../node_modules/third-party-lib1'
  pod 'third-party-lib2', :path => '../node_modules/third-party-lib2'

...
end

Reinstall Pod

After editing the Podfile, we have to make sure to refresh the Pods folder.

$ cd ios
$ rm -rf Pods   // We have to get a fresh copy of our Pods
$ pod install

Run your metro bundler again. This time the error will go away. I hope this will help you!

2 Replies to “React-Native – How to fix Duplicate module name”

Leave a Reply

Your email address will not be published. Required fields are marked *