18

After updating xCode I am facing the below error from a week. I am not able to run app on device. I dont think the issue is with xcode because even if I try to run on android device the same issue occurs.

The issue occurs when we run npm start also with reset option the same error occurs.

The only option is to run on android device after deleting ios build folder.

The error

The following files share their name; please adjust your hasteImpl:
    * <rootDir>/node_modules/react-native/package.json
    * <rootDir>/ios/build/oleo/Build/Products/Debug-iphoneos/oleo.app/assets/node_modules/react-native/package.json

Failed to construct transformer:  DuplicateError: Duplicated files or mocks. Please check the console for more info
    at setModule (/Users/murtazakanpurwala/Documents/Work/Web_Design_Dev/Clients/Oleo/OleoCW/node_modules/jest-haste-map/build/index.js:620:17)
    at workerReply (/Users/murtazakanpurwala/Documents/Work/Web_Design_Dev/Clients/Oleo/OleoCW/node_modules/jest-haste-map/build/index.js:691:9)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Promise.all (index 668) {
  mockPath1: 'node_modules/react-native/package.json',
  mockPath2: 'ios/build/oleo/Build/Products/Debug-iphoneos/oleo.app/assets/node_modules/react-native/package.json'
}
(node:8630) UnhandledPromiseRejectionWarning: Error: Duplicated files or mocks. Please check the console for more info
    at setModule (/Users/murtazakanpurwala/Documents/Work/Web_Design_Dev/Clients/Oleo/OleoCW/node_modules/jest-haste-map/build/index.js:620:17)
    at workerReply (/Users/murtazakanpurwala/Documents/Work/Web_Design_Dev/Clients/Oleo/OleoCW/node_modules/jest-haste-map/build/index.js:691:9)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Promise.all (index 668)
(node:8630) 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)
(node:8630) [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.

Package.json

{
  "name": "oleo",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint .",
    "create-bundle-ios": "react-native bundle --platform ios --dev true --entry-file index.js --bundle-output ios/main.jsbundle",
    "create-bundle-android": "react-native bundle --platform android --dev true --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res"
  },
  "dependencies": {
    "@react-native-community/async-storage": "^1.9.0",
    "@react-native-community/netinfo": "^5.8.0",
    "@react-native-community/push-notification-ios": "^1.1.1",
    "@react-native-firebase/analytics": "^6.7.1",
    "@react-native-firebase/app": "^6.7.1",
    "@react-native-firebase/auth": "^6.7.1",
    "@react-native-firebase/firestore": "^6.7.1",
    "@react-native-firebase/messaging": "^6.7.1",
    "@react-native-firebase/storage": "^6.7.1",
    "accordion-collapse-react-native": "^0.2.10",
    "lodash": "^4.17.15",
    "md5": "^2.2.1",
    "moment": "^2.24.0",
    "react": "16.8.6",
    "react-native": "0.60.5",
    "react-native-chooser": "^1.7.0",
    "react-native-datepicker": "^1.7.2",
    "react-native-draggable-flatlist": "^2.3.2",
    "react-native-exit-app": "^1.1.0",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-image-crop-picker": "^0.25.3",
    "react-native-image-view": "^2.1.8",
    "react-native-material-dropdown": "^0.11.1",
    "react-native-modal": "^11.5.6",
    "react-native-pdf": "^6.1.1",
    "react-native-phone-input": "^0.2.4",
    "react-native-popup-dialog": "^0.18.3",
    "react-native-push-notification": "^3.2.1",
    "react-native-reanimated": "^1.8.0",
    "react-native-screens": "^2.7.0",
    "react-native-snackbar": "^2.2.0",
    "react-native-swiper": "^1.6.0",
    "react-native-webview": "^7.4.2",
    "react-navigation": "^4.3.8",
    "react-navigation-stack": "^1.10.3",
    "rn-fetch-blob": "^0.11.2"
  },
  "devDependencies": {
    "@babel/core": "^7.9.0",
    "@babel/runtime": "^7.9.2",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "eslint": "^6.8.0",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.56.4",
    "react-test-renderer": "16.8.6"
  },
  "jest": {
    "preset": "react-native"
  }
}

I have deleted multiple times node modules, did a fresh install as well but the issue comes up every time.

skyboyer
  • 22,209
  • 7
  • 57
  • 64
murtazamzk
  • 191
  • 1
  • 2
  • 7

10 Answers10

22

The cause for me was that I had two different package.json files with the same value for the name property.

Klas Mellbourn
  • 42,571
  • 24
  • 140
  • 158
  • FYI in my case I accidentally had two copies of some code in two different parts of my project (one was accidentally left over when copying stuff). Deleting the duplicated code fixed it. – owencm Apr 24 '22 at 04:00
11

Because you have two package.json file in your project like package.json and another\\package.json in a sub directory. Also you've get more information on your terminal and in most of times it contains the path : enter image description here

All you have to do is delete the duplicated file in sub directory Not Main file.

Aly
  • 4,425
  • 2
  • 13
  • 23
  • I had this issue with AWS Amplify deleting the duplicate package.json fixed the issue. – johnbumble Jul 20 '21 at 06:34
  • 1
    I don't want to delete the second package.json as it is required by nodejs-mobile-react-native. They have instructed to blacklist those folders in metro in root folder of main project. still getting the error – CrackerKSR Feb 16 '22 at 11:32
  • In my case after deleting the duplicate file. metro server had to be restarted. – Atmaram Aug 01 '22 at 09:25
4

I had took back up of node_module back in project root as "xnode_module". So I have delete back up, it works for me.

Khurshid Ansari
  • 4,638
  • 2
  • 33
  • 52
1
cd ios/
rm -rf build/
xcodebuild clean
cd ..
react native run ios

or check inside project you have must same name project inside

Ali Haider
  • 29
  • 4
1

In my case, I was running npx react-native start in the wrong project. So make sure you are in the correct project.

Kasra
  • 1,959
  • 1
  • 19
  • 29
0

This steps resolved for me.

Close simulator and Xcode, and run this commands.

watchman watch-del-all
rm -rf yarn.lock package-lock.json node_modules
rm -rf android/app/build
rm ios/Pods ios/Podfile.lock 
rm -rf ~/Library/Developer/Xcode/DerivedData
npm install && cd ios && pod update && cd ..
npm start -- --reset-cache
Douglas Soldan
  • 51
  • 1
  • 1
  • 5
0

You may have used the same name for your 2 package.json files. Use different names for your package.json files.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
0

I have the same issue, in my case turns out it reads 2 node_modules folder, even when I have renamed the old folder to something else

Failed to construct transformer:  DuplicateError: Duplicated files or mocks. Please check the console for more info
    at setModule (/Users/tyar/dev/rnstarter/node_modules/jest-haste-map/build/index.js:620:17)
    at workerReply (/Users/tyar/dev/rnstarter/node_modules/jest-haste-map/build/index.js:691:9)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 2159) {
  mockPath1: 'node_modules/react-native/ReactCommon/hermes/inspector/tools/msggen/package.json',
  mockPath2: 'node_modules.bak/react-native/ReactCommon/hermes/inspector/tools/msggen/package.json'
}```
McCandless
  • 43
  • 7
  • 1
    This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/33258826) – Ben Cox Nov 28 '22 at 22:43
0

If you are using sanity in your project try to move outside of your project directory.

davykiash
  • 1,796
  • 5
  • 27
  • 60
-1

Just delete the duplicate package.json file and build again.

Manoj Alwis
  • 1,337
  • 11
  • 24