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

jest-haste-map: Haste module naming collision: react-native #169

Closed
sibelius opened this issue Jul 22, 2019 · 56 comments
Closed

jest-haste-map: Haste module naming collision: react-native #169

sibelius opened this issue Jul 22, 2019 · 56 comments

Comments

@sibelius
Copy link

Current behavior

jest-haste-map: Haste module naming collision: react-native
  The following files share their name; please adjust your hasteImpl:
    * <rootDir>/node_modules/react-native/package.json
    * <rootDir>/../../node_modules/@react-native-community/async-storage/node_modules/react-native/package.json

Failed to construct transformer:  { Error: Duplicated files or mocks. Please check the console for more info
    at setModule (app/packages/app/node_modules/jest-haste-map/build/index.js:620:17)
    at workerReply (app/packages/app/node_modules/jest-haste-map/build/index.js:691:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  mockPath1: 'node_modules/react-native/package.json',
  mockPath2:
   '../../node_modules/@react-native-community/async-storage/node_modules/react-native/package.json' }
(node:29889) UnhandledPromiseRejectionWarning: Error: Duplicated files or mocks. Please check the console for more info
    at setModule (app/packages/app/node_modules/jest-haste-map/build/index.js:620:17)
    at workerReply (app/packages/app/node_modules/jest-haste-map/build/index.js:691:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Expected behavior

It should not duplicate haste

Repro steps

"react-native": "0.60.4",
"@react-native-community/async-storage": "1.5.1",

on a monorepo setup

Install

Environment

  • Async Storage version: "1.5.1",
  • React-Native version: "0.60.4",
  • Platform tested: android
  • Logs/Error that are relevant:
@krizzu krizzu added the LEGACY label Jul 23, 2019
@krizzu
Copy link
Member

krizzu commented Jul 23, 2019

Hi @sibelius ,

Can you provide some info about your monorepo setup? Using yarn workspaces?

@msqar
Copy link

msqar commented Jul 26, 2019

Throwing the same error to me:

jest-haste-map: Haste module naming collision: MyApp
  The following files share their name; please adjust your hasteImpl:
    * <rootDir>/package.json
    * <rootDir>/android/app/src/main/res/raw/package.json

Then this in Android Studio:

/Users/marian-mac/Documents/dev/MyApp/android/app/build/generated/not_namespaced_r_class_sources/debug/processDebugResources/r/com/myapp/R.java: error: invalid symbol name 'com.myapp:raw/package'.

These errors are driving me insane. I've been struggling to make my app work in Android for an entire week already. Using RN 0.60.4 as well.

@sibelius
Copy link
Author

yarn workspaces does not generate any info

@bneigher
Copy link

This is causing me issues too 0.60.4 RN

@proletesseract
Copy link

proletesseract commented Jul 27, 2019

same issue for me but with expo/metro.

node: v10.16.0
yarn: v1.17.3
react-native: v0.60.4
react-native-web: v0.11.5
expo: v3.0.4

jest-haste-map: Haste module naming collision: react-native
  The following files share their name; please adjust your hasteImpl:
    * <rootDir>/package.json
    * <rootDir>/node_modules/react-native/package.json

Failed to construct transformer:  { Error: Duplicated files or mocks. Please check the console for more info
    at setModule (/<project dir>/node_modules/metro/node_modules/jest-haste-map/build/index.js:620:17)
    at workerReply (/<project dir>/node_modules/metro/node_modules/jest-haste-map/build/index.js:691:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  mockPath1: 'package.json',
  mockPath2: 'node_modules/react-native/package.json' }

@bneigher
Copy link

@krizzu
Copy link
Member

krizzu commented Jul 29, 2019

@sibelius that was a question if you're using yarn workspaces in your monorepo.

If so, it seems like you'd want to checkout noHoist options and add react-native from your example there.

@sibelius
Copy link
Author

this is out nohoist setup

"workspaces": {
    "packages": [
      "packages/*"
    ],
    "nohoist": [
      "**/eslint",
      "**/react",
      "**/react*",
      "**/react-native",
      "**/react-native-*",
      "**/@react-native-community",
      "**/@react-native-community/cli",
      "**/@react-native-community/cli-platform-ios",
      "**/@react-native-community/cli-platform-android",
      "**/@react-native-firebase/app/",
      "**/@react-native-firebase/**",
      "**/victory**",
      "**/@sentry",
      "**/@sentry/cli",
      "**/@sentry/wizard",
      "@sentry",
      "@sentry/cli",
      "@sentry/wizard"
    ]
  }

it is breaking for cameraroll as well

@krizzu
Copy link
Member

krizzu commented Jul 30, 2019

@sibelius Sorry I'm no use here, but I believe this is more yarn workspaces/jest setup question, not Async Storage related.

Can you exclude AsyncStorage's React Native dependency transformed modules somehow?

Actually, @msqar, why there's a package.json in <rootDir>/android/app/src/main/res/raw/ ?

@sibelius
Copy link
Author

why jest is causing trouble with react-native packager?

@thymikee
Copy link

@sibelius because Metro uses Haste, which lives in jest-haste-map. Do you have an open source repo with that issue? We could debug. If not, let's just wait for RN 0.61 which removes Haste from RN.
@msqar see facebook/react-native#25645 and #169 (comment).

@sibelius
Copy link
Author

the closest one for our setup is this one https://github.com/entria/entria-fullstack/tree/master/packages/app

@sibelius
Copy link
Author

can we remove haste from this package instead?

@thymikee
Copy link

It's not about this package, it's about jest/hasteImpl.js that sits in RN and allows for such cases apparently.

@dcarnelutti
Copy link

Im just trying to create an empty app for learning purposes. There is no way around to fix this and keep learning?

`Loading dependency graph...jest-haste-map: Haste module naming collision: HelloWorld
The following files share their name; please adjust your hasteImpl:
* /node_modules/react-native/template/package.json
* /package.json

Failed to construct transformer: { Error: Duplicated files or mocks. Please check the console for more info
at setModule (/Users/dario/ReactNativeProjects/HelloWorldApp/HelloWorld/node_modules/jest-haste-map/build/index.js:620:17)
at workerReply (/Users/dario/ReactNativeProjects/HelloWorldApp/HelloWorld/node_modules/jest-haste-map/build/index.js:691:9)
at process._tickCallback (internal/process/next_tick.js:68:7)
mockPath1: 'node_modules/react-native/template/package.json',
mockPath2: 'package.json' }
(node:37886) UnhandledPromiseRejectionWarning: Error: Duplicated files or mocks. Please check the console for more info
at setModule (/Users/dario/ReactNativeProjects/HelloWorldApp/HelloWorld/node_modules/jest-haste-map/build/index.js:620:17)
at workerReply (/Users/dario/ReactNativeProjects/HelloWorldApp/HelloWorld/node_modules/jest-haste-map/build/index.js:691:9)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:37886) 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: 1)
`

using
react-native-cli: 2.0.1
react-native: 0.60.4

node --version
v10.16.1

iMac pro Xcode 10.2.1

@dcarnelutti
Copy link

just changed package.json in templates folder and know it works... at least for testing purposes it's working

@yuanmaole
Copy link

#重复 I add the modules but get the same issue when i start the app
Duplicate module name: react-native
Paths: /Users/mollet/工作/EDA/Client/ios/Pods/React/package.json collides with
/Users/mollet/工作/EDA/Client/node_modules/react-native/package.json
use
"react-native": "0.59.9",
node v11.7.0

@krizzu
Copy link
Member

krizzu commented Aug 5, 2019

@yuanmaole Try following points from our troubleshooting doc

@eranhr
Copy link

eranhr commented Aug 6, 2019

I had the same problem and I solved it for myself. Since I have reproduced it again and again it gives me the thought that it might be the problem to you all as well.

My problem is that I had App2 project directory under (inside) App1 project directory (both created using react-native init <App_>). Once I have removed App2 from App1 directory it all worked fine.

I got it by the indication I got (and you also mentioned it) on <rootDir> and the mockPath1 and mockPath2 in the error messages:

    * <rootDir>/package.json
    * <rootDir>/node_modules/react-native/package.json
   ...
   ...
  mockPath1: 'package.json',
  mockPath2: 'node_modules/react-native/package.json'

@rodrigovive
Copy link

My workaround was rename your project folder and if you use amplify be careful with in metro.config.js
resolver: {
blacklistRE: /#current-cloud-backend/.*/
},

@edgarclerigo
Copy link

I was having the same issue, I have created a backup folder called node_modules_backup as a backup since I has going to remove the node_modules to install all the modules again, after I removed the node_modules_backup folder, the problem stoped and everything starts to run fine.

@pk-mallik
Copy link

Same issue, it was because I was importing package.json inside the app. Look for something like
"import packageJson from '/package'"
One option is to remove the import alternately check this post "facebook/react-native#23482"
I would recommend not importing package.json

@kristoff2016
Copy link

Do you have any solution?

@JullietRUS
Copy link

JullietRUS commented Sep 12, 2019

Do you have any solution?

In my case I followed "React Native Modules setup" instruction from official website for get this error. And the error says, that here are 2 same package.json, first in "node_modules/react-native" and second in "node_modules/[cusom-module]/node_modules/react-native".

So, I deleted "node_modules" from my [custom-module], after that I made this in my app root folder:
rm -rf node_modules/ && yarn cache clean && yarn install && cd ios && pod install - that, in few words, cleans all.

After that my app runs without any problem.
Hope this helps somebody.

@krizzu
Copy link
Member

krizzu commented Sep 13, 2019

This error comes from the fact that there are, indeed, two packages with the same name - they live in different packages' node_modules. Problem is project-dependent.

New Async Storage is a monorepo, with few packages and example project that has dealt with that issue - check out the examples/mobile to get the idea of how to do this.

@maxto024
Copy link

if you have ./template folder delete
and remove template.config.js the templateDir: './template',

this works for me

@leotm
Copy link

leotm commented Sep 24, 2019

...If not, let's just wait for RN 0.61 which removes Haste from RN.

@thymikee Appreciate you mentioning this, resorted to "react-native": "0.61.0-rc.0" for time being after no success resolving this issue.

@kristoff2016
Copy link

Loading dependency graph, done. jest-haste-map: Haste module naming collision: react-native The following files share their name; please adjust your hasteImpl: * <rootDir>/node_modules/react-native/package.json * <rootDir>/ios/build/myapp/Build/Products/Debug-iphoneos/myapp.app/assets/node_modules/react-native/package.json

@kristoff2016
Copy link

Still no solution for it. :(

@leotm
Copy link

leotm commented Sep 25, 2019

Let's hope the release of RN 0.61.x solves 👏

@GreatAuk
Copy link

issue is still in v0.61.1

 OS: macOS Mojave 10.14.4
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 255.41 MB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 12.9.1 - /usr/local/bin/node
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 6.10.3 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
    Android SDK:
      API Levels: 23, 26, 27, 28
      Build Tools: 23.0.1, 26.0.3, 27.0.3, 28.0.1, 28.0.3
      System Images: android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom_64, android-27 | Google APIs Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5522156
    Xcode: 10.2/10E125 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.1 => 0.61.1

@pk-mallik
Copy link

In my case this is happening with any .json file being imported. Finally located the problem as follows.
The release apk is built by two commands, the first one ‘react-native bundle ….’ generates the release bundle and creates the assets including any imported json files.
The second command ‘gradlew assembleRelease’ generates the apk for release. For some reason the second command is trying to overwrite the .json files created by the react-native command and throws an error when it finds the files are already there.
The way round this is to delete the files created by the first command before the second command was run. The workaround for me involved creating a script file in the project root directory which is run from the command prompt to generate the release apk. Script (windows ) is as follows:

_
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res && ^
del android\app\src\main\res\raw*.json && ^
cd android && ^
gradlew.bat assembleRelease && ^
cd ..
_

Hope this helps

@kurtiev
Copy link

kurtiev commented Sep 28, 2019

I came here from another similar issue of package:
react-native-twitter-signin

I just removed folder:
/node_modules/react-native-twitter-signin/node_modules/react-native

Now app runs fine, but how it will work not sure.

this repo using "react-native": "0.58.4"
but now it's 0.61.1

@qburst-ronak
Copy link

qburst-ronak commented Oct 1, 2019

ve-twitter-signin/node_modules/react-native

I was also facing the same issue and tried what you suggested but react-native-twitter-signin on building crashes with

Failed to capture fingerprint of input files for task ':app:bundleReleaseJsAndAssets' property '$1' during up-to-date check.
Could not list contents of '/home/ronak/Project/App/node_modules/react-native-twitter-signin/node_modules/.bin/react-native'. Couldn't follow symbolic link.

kindly please suggest solutions

@supagu
Copy link

supagu commented Oct 2, 2019

if you have ./template folder delete
and remove template.config.js the templateDir: './template',

this works for me

This worked for me also. I examined a project I made a few weeks ago which didn't have the template directory compared to one I made today that has it. So deleting this template stuff seems to be due to a a recent change in the init project script possibly?

@kurtiev
Copy link

kurtiev commented Oct 2, 2019

@RonakCPereira Finally i found another package. It's just fork of same repository without dependencies. So i just changed package.json and no more.
"react-native-login-twitter": "^3.0.1",

@eranhr
Copy link

eranhr commented Oct 2, 2019

Still no solution for it. :(

see @krizzu reply #169 (comment)

@guitorioadar
Copy link

facebook/metro@f3c9862
Huge thanks for @xxsnakerxx above in this section 👏


Temporary solution but worked for me. I've had this problem while building for ios.
Metro bundler copied the package.json into the ios/build folder.
That build folder was not created by xcode itself.

Solution (for ios building problems):

  1. Follow the link above, and edit the file (yeah i know, crappy way of doing something)
cd ios/
rm -rf build/
xcodebuild clean
cd ..

Note, that xcode is going to warn you that the build folder was not created by it, if you did not deleted that beforehand.

react-native run-ios

I have got this solution from hunwalk from this issue

Hope this helps...

Cheers

@Bharatchavan20
Copy link

@guitorioadar Well, this happened with me after running the ios release build. Great catch!!

@joeywu321
Copy link

joeywu321 commented Oct 16, 2019

i clean all build like that:

cd ios/ && rm -rf build/ && xcodebuild clean && cd ..
cd android && gradle clean && gradle assembleDebug --stacktrace && cd ..

and just use

react-native start --reset-cache

then it's ok.

@sibelius
Copy link
Author

fixed upgrading to react-native 61

no more haste issues

\o/

@trackmystories
Copy link

Hey in my case it was because of a previous nodejs app some how made its way into my current project. check and see if you don't have two apps in the same folder

@shubhamram
Copy link

Node Module -> react-native-twitter-signin -> node module
remove that node module inside the react-native-twitter-signin

This is work for me

@developer-digital
Copy link

I came here from another similar issue of package:
react-native-twitter-signin

I just removed folder:
/node_modules/react-native-twitter-signin/node_modules/react-native

Now app runs fine, but how it will work not sure.

this repo using "react-native": "0.58.4"
but now it's 0.61.1

npm install --save GoldenOwlAsia/react-native-twitter-signin#master
instead of
yarn add react-native-twitter-signin

@ahayman
Copy link

ahayman commented Mar 12, 2020

This happened to me when I was trying to use a package that specified an exact version of react native in its package.json:

    "react-native": "0.60.5",

It did not match the version I was using at the time (0.60.6) and so npm install created a nodes_module with that exact version instead of using the one in my project. It was a private repo, so it was easily fixed by changing it to:

    "react-native": "^0.60.5",

@visotechsolutions
Copy link

I was having the same issue, I have created a backup folder called node_modules_backup as a backup since I has going to remove the node_modules to install all the modules again, after I removed the node_modules_backup folder, the problem stoped and everything starts to run fine.

you saved my life, really this issue drive me crazy and your solution work for me, thanks

@bilal-korir
Copy link

bilal-korir commented Mar 30, 2020

In my case was parsing JSON inside a package.json. I put a package.json file inside my folders that I access frequently, so I can import them just by calling the name, like this:
{ "name": "navigation" }

Probably I pressed on key unintentionally while the package.json file was open! clean package.json up fixed my problem. None of the above-mentioned solutions fixed my issue. If none of the solutions worked for you try to think what was the last thing you did before it broke down.

@shacharudi
Copy link

In my case it was a fresh React Native project initiated using the TypeScript template as shown in a reactnative.dev tutorial.

I deleted the template folder and a file named template.config.js from the root folder, ran react-native run-ios and the issue was fixed.

@manjujeewa
Copy link

I was having the same issue, I have created a backup folder called node_modules_backup as a backup since I has going to remove the node_modules to install all the modules again, after I removed the node_modules_backup folder, the problem stoped and everything starts to run fine.

This solution worked for me as well

@xnzj
Copy link

xnzj commented Jun 9, 2020

@edgarclerigo
You really save my time and brain cells. Thanks a lot.

@gkdg
Copy link

gkdg commented Jun 25, 2020

for those who use AWS Amplify and having duplicated file error from jest-haste-map you can ignore the package.json file inside the #current-cloud-backend folder by adding below code inside metro.config.js file:

module.exports = {
  resolver: {
  blacklistRE: /#current-cloud-backend/
  }
};

@andrekovac
Copy link

andrekovac commented Jul 18, 2020

In case you're using Typescript, don't make the mistake to rename metro.config.js to metro.config.ts. It won't work and you'll continue to have the problem! Keep the .js!

@wordisthebird
Copy link

for those who use AWS Amplify and having duplicated file error from jest-haste-map you can ignore the package.json file inside the #current-cloud-backend folder by adding below code inside metro.config.js file:

module.exports = {
  resolver: {
  blacklistRE: /#current-cloud-backend/
  }
};

Works prefectly Feb 2021! Thank you!

@exokalabaw
Copy link

for those who use AWS Amplify and having duplicated file error from jest-haste-map you can ignore the package.json file inside the #current-cloud-backend folder by adding below code inside metro.config.js file:

module.exports = {
  resolver: {
  blacklistRE: /#current-cloud-backend/
  }
};

Works prefectly Feb 2021! Thank you!

Hi sorry for the stupid question, but I'm already two days into trying to get this to work but where exactly is the metro.config.js file? I also tried adding one to the root as instructed in some other fix but it didn't seem to work. .

@hackeru2
Copy link

Ive tried everything until i saw that ive change my node_modules to _node_modules and for some reason it was bundeled and create the duplicate error

@Yashism
Copy link

Yashism commented Aug 31, 2022

For me it was showing
mockPath1: 'amplify\#current-cloud-backend\function\Gifchat1PostConfirmation\src\package.json',
mockPath2: 'amplify\backend\function\Gifchat1PostConfirmation\src\package.json'

So I deleted the mockPath1 and it worked

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

No branches or pull requests