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: Duplicate module name: sample-node-project #120

Closed
aerielcruz opened this issue Sep 18, 2018 · 9 comments
Closed

ERROR: Duplicate module name: sample-node-project #120

aerielcruz opened this issue Sep 18, 2018 · 9 comments

Comments

@aerielcruz
Copy link

aerielcruz commented Sep 18, 2018

  • Project: nodejs-mobile-react-native
  • Version: v0.3.0
  • Mobile device: Android
  • Mobile OS and version: Oreo
  • Development Node.js: v10.9.0
  • Development platform: Darwin Kernel Version 17.7.0

React Native - Duplicate Module Name Error
Im trying to implement js-ipfs-api to my RN app but it requires Node.js v6 or higher but this problem I can't even get through.

Metro Bundler has encountered and internal error, please check your terminal error output for more details

Loading dependency graph...(node:88726) UnhandledPromiseRejectionWarning: Error: jest-haste-map: @providesModule naming collision:
  Duplicate module name: sample-node-project
  Paths: /Users/username/Project/android/app/build/intermediates/assets/debug/nodejs-project/package.json collides with /Users/username/Project/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/Project/node_modules/metro/node_modules/jest-haste-map/build/index.js:462:17)
    at workerReply (/Users/username/Project/node_modules/metro/node_modules/jest-haste-map/build/index.js:512:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:88726) 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:88726) [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.

This error showed after running react-native run-android in my create-react-native-app and made a separate react-native init project to test the error.
NDK is installed as well as CMAKE and my SDK and NDK directory are in my local.properties.

To reproduce issue:

  1. Create a new RN app
    react-native init TestProject
    (or you may try $ create-react-native-app if there could be a difference)
  2. cd TestProject
  3. npm install nodejs-mobile-react-native --save
  4. react-native link nodejs-mobile-react-native
  5. export ANDROID_HOME=/Users/username/Library/Android/sdk
  6. export ANDROID_NDK_HOME=/Users/username/Library/Android/sdk/ndk-bundle (I've installed NDK in Android Studio's SDK Manager)
  7. Run react-native run-android to test
  8. Go to nodejs-assets/nodejs-project/ path and rename sample-main.js to main.js and sample-package.json to package.json
  9. Run react-native run-android and check your Metro Bundler, you may or may not see an error jest-haste-map: @providesModule naming collision: ... but it still ran so there shouldn't be a problem right?? Haha nope
  10. Now quit/terminate Metro Bundler and run react-native run-android again
  11. Error shown above after that

I've already looked into this Runtime Support: React-Native #1254 and done a ton of googling in terms of this issue but there aren't a lot of examples or issues with the use of nodejs-mobile-react-native.

This may be an unstable build but as of now this is the only option to implement nodejs in RN so I get to interact with IPFS.

@jaimecbernardo
Copy link
Member

Hi @aerielcruz ,

Thank you for reporting this. This is caused by the react-native bundler finding duplicate files from the nodejs-project, as these are copied by the build process to be included in the application's assets, though it used to be a warning.

You can add the conflicting paths to the bundler blacklist by adding a rn-cli.config.js file to your react-native project root path with the following contents:

const blacklist = require('metro/src/blacklist');

module.exports = {
  getBlacklistRE: function() {
    return blacklist([
      /nodejs-assets\/.*/,
      /android\/.*/,
      /ios\/.*/
    ]);
  },
};

Here's an example from the file inside a sample: https://github.com/janeasystems/nodejs-mobile-samples/blob/dd008acf75f3202ee4ab64b3822ab4bfa6e6f965/react-native/UseMultipleChannels/rn-cli.config.js

Please let us know if this change allows your application to build.

@jaimecbernardo
Copy link
Member

Hi @aerielcruz ,
As a follow-up, react-native has changed the way to do this in the most recent v0.57 release. The rn-cli.config.js contents should be this, if you are running react-native >= 0.57:

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

module.exports = {
  resolver:{
    blacklistRE: blacklist([
      /nodejs-assets\/.*/,
      /android\/.*/,
      /ios\/.*/
    ])
  },
};

@aerielcruz
Copy link
Author

aerielcruz commented Sep 19, 2018

Thanks for the follow-up @jaimecbernardo !
This fixed my issue. Was also about to comment about the change of rn-cli.config.js if react-native >= 0.57 and so far it worked on a fresh react-native init build.

I also tried it on my existing create-react-native-app project but then new problems came up which is unrelated but it still works nonetheless.

Might give an update when adding new packages. Again thanks! 😄

@jaimecbernardo
Copy link
Member

Thank you for the feedback. Instructions to trouble shoot this have been added to the README.md, as well: https://github.com/janeasystems/nodejs-mobile-react-native/tree/ed727edea17e8a9e1a85cef3413becc83b8a0328#duplicate-module-name

@hayr-hotoca
Copy link

Hi @jaimecbernardo jaimecbernardo

I still have the error and cannot start the server.

Here is the log:

Loading dependency graph...jest-haste-map: Haste module naming collision: sample-node-project
The following files share their name; please adjust your hasteImpl:
* /nodejs-assets/nodejs-project/package.json
* /ios/build/nodejsmobile/Build/Products/Debug-iphonesimulator/nodejsmobile.app/nodejs-project/package.json

Failed to construct transformer: { Error: Duplicated files or mocks. Please check the console for more info
at setModule (/Users/huulinh/Desktop/node/reactnative/nodejsmobile/node_modules/jest-haste-map/build/index.js:620:17)
at workerReply (/Users/huulinh/Desktop/node/reactnative/nodejsmobile/node_modules/jest-haste-map/build/index.js:691:9)
at
at process._tickCallback (internal/process/next_tick.js:188:7)
mockPath1: 'nodejs-assets/nodejs-project/package.json',
mockPath2: 'ios/build/nodejsmobile/Build/Products/Debug-iphonesimulator/nodejsmobile.app/nodejs-project/package.json' }
(node:2465) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Duplicated files or mocks. Please check the console for more info
(node:2465) [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: Duplicated files or mocks. Please check the console for more info
at setModule (/Users/huulinh/Desktop/node/reactnative/nodejsmobile/node_modules/jest-haste-map/build/index.js:620:17)
at workerReply (/Users/huulinh/Desktop/node/reactnative/nodejsmobile/node_modules/jest-haste-map/build/index.js:691:9)
at
at process._tickCallback (internal/process/next_tick.js:188:7)

@acerbastimur
Copy link

I'm having this issue as well.

@mohit23x
Copy link

the issue still exist

@QuinsZouls
Copy link

the issue still exist

For the new versions of react-native (+0.60) you have to modify the metro-config.js file, just add the resolver:

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

/**
 * Metro configuration for React Native
 * https://github.com/facebook/react-native
 *
 * @format
 */

module.exports = {
  resolver:{
    blacklistRE: blacklist([
      /nodejs-assets\/.*/,
      /android\/.*/,
      /ios\/.*/
    ])
  },
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  },
};

@carsonxw
Copy link

For me i need to use const blacklist = require('metro-config/src/defaults/exclusionList'); on RN 0.70.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants