question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RN - Error: jest-haste-map: @providesModule naming collision

See original GitHub issue

Reporting this error here as well, as suggested in the corresponding react-native issue: https://github.com/facebook/react-native/issues/21242#issuecomment-424132088

It’s related to react-native’s usage of metro, where a plugin might need to instruct metro to ignore some paths in the react-native project. Discussion here might helpful, as there might already be a way to achieve this.

Here’s the original issue:

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.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:12
  • Comments:33 (2 by maintainers)

github_iconTop GitHub Comments

60reactions
nvmanhcommented, Feb 15, 2019

@jaimecbernardo confirmed your solution works by adding:

const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
  resolver:{
    blacklistRE: blacklist([
      /nodejs-assets\/.*/,
      /android\/.*/,
      /ios\/.*/
    ])
  },
};
57reactions
thg303commented, Apr 3, 2019

@shreyasb07 I see you have metro.config.js there too. I think in newer versions metro uses that instead of rn-cli.config.js, so try putting content there too. if that worked, you can remove rn-cli.config.js.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: jest-haste-map: @providesModule naming collision ...
json This error is caused by a @providesModule declaration with the same name across two different files.
Read more >
Error: jest-haste-map: Haste module naming collision
json This error is caused by `hasteImpl` returning the same name for different files. import React from "react"; import {StyleSheet, View} from ...
Read more >
React Native @providesModule naming collision error - Medium
This error is caused by a @providesModule declaration with the same name across two different files.
Read more >
[Solved]-Error: jest-haste-map - appsloveworld
Coding example for the question Error: jest-haste-map: @providesModule naming collision when using a local dependency-React Native.
Read more >
Jest-haste-map: Haste module naming collision
jest-haste-map : Haste module naming collision:myapp jest-haste-map: ... Failed to construct transformer: { Error: Duplicated files or mocks.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found