Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: jest-haste-map: @providesModule naming collision #21242

Closed
jaimecbernardo opened this issue Sep 21, 2018 · 33 comments
Closed

Error: jest-haste-map: @providesModule naming collision #21242

jaimecbernardo opened this issue Sep 21, 2018 · 33 comments
Labels
Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.

Comments

@jaimecbernardo
Copy link

Environment

  React Native Environment Info:
    System:
      OS: macOS High Sierra 10.13.6
      Memory: 1.69 GB / 8.00 GB
      Shell: 4.4.12 - /usr/local/bin/bash
    Binaries:
      Node: 8.9.2 - /usr/local/bin/node
      npm: 5.5.1 - /usr/local/bin/npm
      Watchman: 4.7.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
      Android SDK:
        Build Tools: 23.0.1, 25.0.0, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.1, 27.0.3, 28.0.0, 28.0.1
        API Levels: 23, 24, 25, 26, 27
    IDEs:
      Android Studio: 3.0 AI-171.4443003
      Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.5.0 => 16.5.0 
      react-native: 0.57.0 => 0.57.0 
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7

Description

The nodejs-mobile-react-native plugin runs a nodejs project in a react-native application. It creates a nodejs-project folder in the react-native's project root folder, which will be copied in the build process to be included in the mobile application assets, which means the Bundler will detect duplicate modules.

Before react-native version 0.56, this duplication caused a warning while the bundler was starting, but the mobile application was still able to function and get the react-native files from the bundler. In and after version 0.56, the bundler will now throw an error when the mobile application tries to get the bundle from the development machine:
error: bundling failed: Error: jest-haste-map: @providesModule naming collision:

Before react-native version 0.56, it was possible to use the plugin without creating a rn-cli.config.js file in the react-native project, as this was only a warning, but now creating a rn-cli.config.js file in the main project with a blacklist for the Metro bundler is mandatory for using the plugin: https://github.com/janeasystems/nodejs-mobile-react-native/tree/ed727edea17e8a9e1a85cef3413becc83b8a0328#duplicate-module-name

Since this is now an error that won't allow the application to work, is there something that can be done from inside the plugin to have the Metro bundler ignore some paths?

Thank you, in advance.

Reproducible Demo

Before react-native version 0.56, the application is able to run successfully.

react-native init DuplicateModulesWarning --version 0.55.4
cd DuplicateModulesWarning
npm install nodejs-mobile-react-native
mv nodejs-assets/nodejs-project/sample-package.json nodejs-assets/nodejs-project/package.json
mv nodejs-assets/nodejs-project/sample-main.js nodejs-assets/nodejs-project/main.js
react-native link
react-native run-android

The react packager throws warnings but the application can still run and get the bundle from the development machine:

Loading dependency graph, done.
jest-haste-map: @providesModule naming collision:
  Duplicate module name: sample-node-project

In and after react-native version 0.56, the application will fail to run due to the bundler failing:

react-native init DuplicateModulesError --version 0.56.0
cd DuplicateModulesError
npm install nodejs-mobile-react-native
mv nodejs-assets/nodejs-project/sample-package.json nodejs-assets/nodejs-project/package.json
mv nodejs-assets/nodejs-project/sample-main.js nodejs-assets/nodejs-project/main.js
react-native link
react-native run-android

The same warning is still thrown but now there is an additional error when the application running in the device tries to get the bundle from the development machine:

error: bundling failed: Error: jest-haste-map: @providesModule naming collision:
  Duplicate module name: sample-node-project
  Paths: /Users/username/temp-projects/DuplicateModulesError/nodejs-assets/nodejs-project/package.json collides with /Users/username/temp-projects/DuplicateModulesError/android/build/nodejs-assets/nodejs-project/package.json

This error is caused by a @providesModule declaration with the same name across two different files.
    at setModule (/Users/username/temp-projects/DuplicateModulesError/node_modules/jest-haste-map/build/index.js:446:17)
    at workerReply (/Users/username/temp-projects/DuplicateModulesError/node_modules/jest-haste-map/build/index.js:496:9)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
 BUNDLE  [android, dev] ../../index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.

Sometimes this error won't occur in the first run, so there's probably a timing issue here. If it doesn't occur in the first run, close the Metro Bundler and run react-native run-android again.

@RSNara
Copy link
Contributor

RSNara commented Sep 24, 2018

Since this has more to do with Metro than it does with react native, it may be more productive to have this discussion over at facebook/metro instead of here.

@jaimecbernardo
Copy link
Author

I've opened the issue at the metro's repo, as suggested: facebook/metro#265

While this has to do with Metro, it seems to be caused by react-native's usage of Metro, since metro provides a way for applications to be configured and avoid this error, which can be used in react-native's applications through rn-cli.config.js.
react-native plugins are unable to use this configuration file, though, as far as I'm aware.

@rafeca
Copy link
Contributor

rafeca commented Sep 25, 2018

As I've suggested in the linked Metro issue, I think that the fix should be done in the default Metro config for RN apps (which lives here).

@r01010010
Copy link

r01010010 commented Oct 20, 2018

I'm getting same error. In my case has to do with 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)

@josmithua
Copy link

@r01010010 Did you resolve this? I'm having the same issue.

@mosinbagban
Copy link

@r01010010 Did you resolve this issue? I am getting same issue for saleforce mobile sdk sample code
Error is
This error is caused by hasteImpl returning the same name for different files.
(node:6352) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will ter
minate the Node.js process with a non-zero exit code.
(node:6352) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): Error: jest-haste-map: Haste module naming collision:
Duplicate module name: react-native
Paths: D:\project\ReactNative\SalesforceMobileSDK-Templates-master\SmartSyncExplorerReactNative\node_modules\react-native-force\node_modules\react-n
ative\package.json collides with D:\project\ReactNative\SalesforceMobileSDK-Templates-master\SmartSyncExplorerReactNative\node_modules\react-native\pa
ckage.json

This error is caused by hasteImpl returning the same name for different files.

@mjstelly
Copy link

mjstelly commented Dec 8, 2018

As I've suggested in the linked Metro issue, I think that the fix should be done in the default Metro config for RN apps (which lives here).

This link is dead, FYI.

@mjstelly
Copy link

mjstelly commented Dec 8, 2018

This happened to me after linking App Center's SDK's yarn add appcenter appcenter-analytics appcenter-crashes --exact to my app with react-native link.

The first error message reads:

  Duplicate module name: react-native
  Paths: /Users/michaelstelly/Documents/projects/myproj/ios/Pods/React/package.json collides with /Users/michaelstelly/Documents/projects/myproj/node_modules/react-native/package.json```

@jamalx31
Copy link

jamalx31 commented Dec 10, 2018

I start to get this error after upgrading to rn 0.57.7. the jsbundler started to complain about every npm package that includes react-native. so I added rn-cli.config.js

const blacklist = require('metro-config/src/defaults/blacklist');

module.exports = {
    resolver: {
        blacklistRE: blacklist([
            /node_modules\/.*\/node_modules\/react-native\/.*/,
        ])
    },
};

@mjstelly
Copy link

Is that a fix or just triage @jamalx31?

@jamalx31
Copy link

@mjstelly a fix. at least in my case.
Give it a try

@mosinbagban
Copy link

@jamalx31 This is not working in my case. same problem.

when I tried to make bundle I am getting following error

This error is caused by hasteImpl returning the same name for different files.

Error: jest-haste-map: Haste module naming collision:
Duplicate module name: react-native
Paths: D:\project\ReactNative\SalesforceMobileSDK-Templates-master\SmartSyncExplorerReactNative\node_modules\react-native-force\node_modules\react-n
ative\package.json collides with D:\project\ReactNative\SalesforceMobileSDK-Templates-master\SmartSyncExplorerReactNative\node_modules\react-native\pa
ckage.json

This error is caused by hasteImpl returning the same name for different files.
at setModule (D:\project\ReactNative\SalesforceMobileSDK-Templates-master\SmartSyncExplorerReactNative\node_modules\jest-haste-map\build\index.js:
551:17)
at workerReply (D:\project\ReactNative\SalesforceMobileSDK-Templates-master\SmartSyncExplorerReactNative\node_modules\jest-haste-map\build\index.j
s:613:9)
at
at process._tickCallback (internal/process/next_tick.js:188:7)

can anybody suggest how to resolve this?

@jamalx31
Copy link

jamalx31 commented Dec 11, 2018

@mosinbagban I think it didn't work for you cuz you are on Windows. try to update the regex.
(Windows use backslash \ in the path)

probably this will work for you
/node_modules\\.*\\node_modules\\react-native\\.*/

@kelset kelset added the Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. label Dec 12, 2018
@kelset
Copy link
Contributor

kelset commented Dec 12, 2018

Link to the Metro issue facebook/metro#265, please refer to that.

@kelset kelset closed this as completed Dec 12, 2018
@mjstelly
Copy link

mjstelly commented Dec 12, 2018 via email

@lattice0
Copy link

im having this problem but on react-native-desktop

@hardikmobileappsdev
Copy link

hardikmobileappsdev commented Mar 12, 2019

I'm getting same issue here,

Error: jest-haste-map: Haste module naming collision:
Duplicate module name: react-native
Paths: /Users/sagarr/Documents/ReactNativeProject/RNpay/ios/Pods/React/package.json collides with /Users/sagarr/Documents/ReactNativeProject/RNpay/node_modules/react-native/package.json

This error is caused by hasteImpl returning the same name for different files.
at setModule (/Users/sagarr/Documents/ReactNativeProject/RNpay/node_modules/jest-haste-map/build/index.js:569:17)
at workerReply (/Users/sagarr/Documents/ReactNativeProject/RNpay/node_modules/jest-haste-map/build/index.js:641:9)
at process._tickCallback (internal/process/next_tick.js:68:7)
::ffff:127.0.0.1 - - [12/Mar/2019:12:32:43 +0000] "GET /index.bundle?platform=ios&dev=true&minify=false HTTP/1.1" 200 - "-" "RNpay/1 CFNetwork/897.15 Darwin/17.5.0"
Error: jest-haste-map: Haste module naming collision:
Duplicate module name: react-native
Paths: /Users/sagarr/Documents/ReactNativeProject/RNpay/ios/Pods/React/package.json collides with /Users/sagarr/Documents/ReactNativeProject/RNpay/node_modules/react-native/package.json

This error is caused by hasteImpl returning the same name for different files.
at setModule (/Users/sagarr/Documents/ReactNativeProject/RNpay/node_modules/jest-haste-map/build/index.js:569:17)
at workerReply (/Users/sagarr/Documents/ReactNativeProject/RNpay/node_modules/jest-haste-map/build/index.js:641:9)
at process._tickCallback (internal/process/next_tick.js:68:7)

@edritech93
Copy link

edritech93 commented Apr 8, 2019

I have same issue, please help

@stephane-r
Copy link

Same issue after upgrade react-native to latest version :/

@asilvestre87
Copy link

asilvestre87 commented Apr 23, 2019

Same issue in RN 0.59.4, this is my Podfile:
-- Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

target 'mynewapp' do
-- Uncomment the next line if you're using Swift or would like to use dynamic frameworks
-- use_frameworks!

-- Pods for mynewapp

-- Pods for ReactPushNotifications - Add these lines
pod 'Firebase/Core'
pod 'Firebase/Messaging', '~> 5.15.0'

pod 'RNGestureHandler', :path => '../node_modules/react-native-gesture-handler'
pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'
pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'

target 'mynewapp-tvOSTests' do
inherit! :search_paths
-- Pods for testing
end

target 'mynewappTests' do
inherit! :search_paths
-- Pods for testing
end

end

@ghost
Copy link

ghost commented May 3, 2019

@jamalx31 could you please let me know where to add this code?

const blacklist = require('metro-config/src/defaults/blacklist');

module.exports = {
    resolver: {
        blacklistRE: blacklist([
            /node_modules\/.*\/node_modules\/react-native\/.*/,
        ])
    },
};

@irohitb
Copy link

irohitb commented May 4, 2019

@muhammadwfa you need to create rn-cli.config.js file and add it inside it

@harkirat1892
Copy link

Please check out this solution. It was the problem I had, and the answer helped me get it solved:

invertase/react-native-firebase#414 (comment)

@evelant
Copy link

evelant commented May 7, 2019

@muhammadwfa I had to put it in metro.config.js instead of rn-cli.config.js. I also had to use the solution posted in the post above mine, configuring my podfile to specifically resolve react as ../node_modules/react-native. Without these two tweaks I was constantly running into issues with things linking to the wrong version of react.

@leemcmullen
Copy link

I still couldn't get it to work, even with updating the Podfile to reference node_modules and configuring metro.config.js with the blacklist.

It turns out my issue was that there was an unused React directory lying around within ios/Pods which was causing the conflict. After I removed that, metro started first time.

@WormGirl
Copy link

I am getting this error because the project is nested. this mean project in project .

@martinfrouin
Copy link

martinfrouin commented Jun 18, 2019

Same error on RN 0.59.X
rn-cli.config.js doesn't work. I fixed it by putting jamalx31's code on a metro.config.js file

I start to get this error after upgrading to rn 0.57.7. the jsbundler started to complain about every npm package that includes react-native. so I added rn-cli.config.js

const blacklist = require('metro-config/src/defaults/blacklist');

module.exports = {
    resolver: {
        blacklistRE: blacklist([
            /node_modules\/.*\/node_modules\/react-native\/.*/,
        ])
    },
};

@lupelius
Copy link

OK About to board a plane so can't find out which bit worked but following metro config works finally:

`/**

module.exports = {
resolver:{
blacklistRE: blacklist([
/react-native/local-cli/core/fixtures./,
/node_modules/.
/node_modules/react-native/./,
/nodejs-assets/.
/,
/android/./,
/ios/.
/,
/node_modules\.\node_modules\react-native\./,
/nodejs-assets\./,
/android\.
/,
/ios\./
])
},
getBlacklistRE () {
return blacklist([
/react-native/local-cli/core/fixtures.
/,
/node_modules/./node_modules/react-native/./,
/nodejs-assets/./,
/android/.
/,
/ios/./,
/node_modules\.
\node_modules\react-native\./,
/nodejs-assets\.
/,
/android\./,
/ios\.
/
])
},
transformer: {
getBlacklistRE () {
blacklist([
/node_modules/./node_modules/react-native/./,
/nodejs-assets/./,
/android/.
/,
/ios/./,
/node_modules\.
\node_modules\react-native\./,
/nodejs-assets\.
/,
/android\./,
/ios\.
/
])
},
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
};`

@0xcodezero
Copy link

0xcodezero commented Jul 8, 2019

@lupelius Could you please post a well formatted code snippet, of you can made a gist on GitHub, as it seems that there is a missing characters and It gives a regular expression error.

@rnnyrk
Copy link

rnnyrk commented Jul 17, 2019

Also have this isse with 0.59. Like @leemcmullen said I've got a new React folder in Pods since I've installed @react-native-community/async-storage, but after I deleted it I can't build my project anymore; Build input file cannot be found: '/project/ios/Pods/React/React/Base/RCTBridge.m'. How can I get this working with 0.59 and the seperate async-storage?

@kwokhou
Copy link

kwokhou commented Aug 10, 2019

I still couldn't get it to work, even with updating the Podfile to reference node_modules and configuring metro.config.js with the blacklist.

It turns out my issue was that there was an unused React directory lying around within ios/Pods which was causing the conflict. After I removed that, metro started first time.

surprisingly this fixes the issue in my case, even though I as compiling for android release. thx man.

@mohammad-goldast
Copy link

mohammad-goldast commented Oct 2, 2019

I just replaced "name": "react-native", to "name": "react-native-", in /Ios/Pods/React/Package.json :)

cooperka added a commit to cooperka/react-native-immutable-list-view that referenced this issue Oct 19, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Dec 12, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Dec 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.
Projects
None yet
Development

No branches or pull requests