5
votes

I'm using a local module in package.json that also has react-native as a dependency.

In my APP package.json:

"react": "16.4.1",
"react-native": "0.56.0",
"react-native-services": "file:///Users/R01/Projects/react-native-services"

In my react-native-services package.json:

"react": "16.4.1",
"react-native": "0.56.0"

So when running react-native run-android the Metro Bundler throws:

Looking for JS files in
   /Users/R01/Projects/RNApp
   /Users/R01/Projects/react-native-services 


Metro Bundler ready.

Loading dependency graph...(node:72824) UnhandledPromiseRejectionWarning: Error: jest-haste-map: @providesModule naming collision:
  Duplicate module name: Sample
  Paths: /Users/R01/Projects/react-native-services/node_modules/react-native/Libraries/Sample/package.json collides with /Users/R01/Projects/RNApp/node_modules/react-native/Libraries/Sample/package.json

 This error is caused by a @providesModule declaration with the same name across two different files.
    at setModule (/Users/R01/Projects/RNApp/node_modules/jest-haste-map/build/index.js:446:17)
    at workerReply (/Users/R01/Projects/RNApp/node_modules/jest-haste-map/build/index.js:496:9)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)
(node:72824) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:72824) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
error: bundling failed: Error: jest-haste-map: @providesModule naming collision:
  Duplicate module name: Sample
  Paths: /Users/R01/Projects/react-native-services/node_modules/react-native/Libraries/Sample/package.json collides with /Users/R01/Projects/RNApp/node_modules/react-native/Libraries/Sample/package.json

This error is caused by a @providesModule declaration with the same name across two different files.
    at setModule (/Users/R01/Projects/RNApp/node_modules/jest-haste-map/build/index.js:446:17)
    at workerReply (/Users/R01/Projects/RNApp/node_modules/jest-haste-map/build/index.js:496:9)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)

I already tried:

  • With both npm and yarn (upgraded) installations but react-native run-android throws always the same error.
  • watchman watch-del-all rm -rf node_modules && npm install rm -fr $TMPDIR/react-* npm cache clean npm start -- --reset-cache
5

5 Answers

1
votes
watchman watch-del-all

rm -rf node_modules && npm install

rm -fr $TMPDIR/react-*
npm cache clean
npm start -- --reset-cache

for more check out here

1
votes

Faced same issue Resolved it !!

All the npm packages in project have node modules. Make sure that node_modules directory inside packages should not include already present node module.

In my case react-native was present in node_modules of my project as well as node_modules of another forked library.

As the library was forked, I could remove node_modules directory from it and the issue got resolved.

0
votes

I respond myself.

As a temporary solution, and given putting the dependencies in peerDependencies didn't work either, I've put the react and react-native in devDependencies of the react-native-services package.

0
votes

I also got the same error. I tried below steps, its works like a charming.

Please remove all react-native specific folders from "%appdata%\Temp" and then try below commands:

rimraf node_modules
npm cache clean --force
npm install
rm -rf ios/build

Change /Users/Jebasuthan/XcodeProject/Game/ios/Pods/React/package.json to something else

non recursive

Xcode change

0
votes
const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
 resolver: {
    blacklistRE: blacklist([
        /node_modules\/.*\/node_modules\/react-native\/.*/,
    ])
 },
};