Jest: Naming collision error when running react-native packager

Created on 5 Dec 2016  路  9Comments  路  Source: facebook/jest

Do you want to request a feature or report a bug?
Report a bug

What is the current behavior?
In a react-native project I get the following naming collision error while running packager, that seems to come from jest-haste-map:

jest-haste-map: @providesModule naming collision:
  Duplicate module name: inquirer
  Paths: /CoolProject/node_modules/react-native/node_modules/yeoman-generator/node_modules/inquirer/package.json collides with /CoolProject/node_modules/react-native/node_modules/inquirer/package.json

This warning is caused by a @providesModule declaration with the same name across two different files.
jest-haste-map: @providesModule naming collision:
  Duplicate module name: lodash
  Paths: /CoolProject/node_modules/react-native/node_modules/lodash/package.json collides with /CoolProject/node_modules/react-native/node_modules/inquirer/node_modules/lodash/package.json

This warning is caused by a @providesModule declaration with the same name across two different files.
jest-haste-map: @providesModule naming collision:
  Duplicate module name: cli-width
  Paths: /CoolProject/node_modules/react-native/node_modules/yeoman-generator/node_modules/cli-width/package.json collides with /CoolProject/node_modules/react-native/node_modules/cli-width/package.json

This warning is caused by a @providesModule declaration with the same name across two different files.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal repository on GitHub that we can npm install and npm test.
1) Dependencies for which running react-native start --reset-cache throws the "naming collision error":

"dependencies": {
    "inquirer": "^0.10.1",
    "lodash": "^4.16.4",
    "yeoman-generator": "^0.24.1",
    "react": "15.3.1",
    "react-native": "0.36.0"
  },

2) Dependencies for which react-native start --reset-cache is executed successfully:

"dependencies": {
    "inquirer": "^0.12.0",
    "lodash": "^3.10.1",
    "yeoman-generator": "^0.21.2",
    "react": "15.3.1",
    "react-native": "0.36.0"
  },

What is the expected behavior?
Packager should run successfully.

Run Jest again with --debug and provide the full configuration it prints. Please mention your node and npm version and operating system.
npm: 3.10.8
node: v7.0.0

Needs More Info React Native

Most helpful comment

jest-haste-map is not the right place to be checking for package collisions (at least in Metro's case), because it doesn't discriminate between dependencies and devDependencies. Ideally, it would ignore devDependencies, but it's impossible to do that without building a dependency graph (which is something that Metro does).

With that said, I guess Metro should just disable the throwOnModuleCollision option and maintain its own package cache. Otherwise, jest-haste-map will remove "duplicate" packages from the module map, which Metro does not respond kindly to.

All 9 comments

Does this still happens on Jest 18.1 and react-native 38+ with Jest's "preset": "react-native" in config?

This is still happening, I'm using Jest 18.1 with react-native 0.41

Same issue here.

I'm using Jest 19.0.2 with react-native 0.43.2. It was fine with react-native 0.42.0.

I made an issue on the react-native page too: https://github.com/facebook/react-native/issues/13364

Can anybody please provide me solution for this, i have same issue.

It is broken with react-native 0.43.2

It is working with this packages.config

  "dependencies": {
    "fetch-ponyfill": "^4.0.0",
    "lodash": "^4.17.4",
    "moment": "^2.18.1",
    "react": "~15.4.1",
    "react-native": "0.42",
    "react-native-code-push": "^2.0.2-beta",
    "react-native-easy-grid": "^0.1.8",
    "react-native-loading-spinner-overlay": "^0.4.4",
    "react-native-modalbox": "^1.3.9",
    "react-native-reactive": "0.0.3",
    "react-native-router-flux": "^3.38.0",
    "react-native-scrollable-tab-view": "^0.7.4",
    "react-native-simple-store": "^1.1.0",
    "react-native-tableview": "^1.7.0",
    "react-native-vector-icons": "^4.0.1",
    "url-parser": "0.0.1"
  },
  "devDependencies": {
    "babel-jest": "19.0.0",
    "babel-preset-react-native": "1.9.1",
    "jest": "19.0.2",
    "querystring": "^0.2.0",
    "react-test-renderer": "15.4.2",
    "url": "^0.11.0"
  },

also see: https://github.com/andreipt/VanillaReactNative

I'm running into this. 馃槩

Is Jest supposed to deduplicate packages with the same name and version? There should at least be an option for such a thing. It would definitely help solve https://github.com/facebook/metro/issues/350.

Jest version: 23.6.0

Jest has removed its haste support, the implementation comes from RN's preset: https://github.com/facebook/react-native/blob/02697291ff41ddfac5b85d886e9cafa0261c8b98/jest/hasteImpl.js

Probably worth an issue on RN? I _think_ this isn't something to fix here, I might be wrong, though!

@SimenB I'm referring to this error specifically:

https://github.com/facebook/jest/blob/adf2b3c73f967e9c07308c512c4df300d770f295/packages/jest-haste-map/src/index.js#L433-L443

There's currently no way to configure jest-haste-map to ignore "module" collisions (package collisions in my case) when they have identical SHA-1 strings.

jest-haste-map is not the right place to be checking for package collisions (at least in Metro's case), because it doesn't discriminate between dependencies and devDependencies. Ideally, it would ignore devDependencies, but it's impossible to do that without building a dependency graph (which is something that Metro does).

With that said, I guess Metro should just disable the throwOnModuleCollision option and maintain its own package cache. Otherwise, jest-haste-map will remove "duplicate" packages from the module map, which Metro does not respond kindly to.

Was this page helpful?
0 / 5 - 0 ratings