React Native DuplicateError: Duplicated files or mocks

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.

3 thoughts on “React Native DuplicateError: Duplicated files or mocks”

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

    Reply

Leave a Comment