React Native重复错误:重复的文件或模拟

1sbrub3j  于 2022-11-25  发布在  React
关注(0)|答案(8)|浏览(155)

更新xCode后,我面临着下面的错误从一个星期。我不能运行设备上的应用程序。我不认为这个问题是与xcode,因为即使我试图运行在android设备上发生同样的问题。
当我们使用重置选项运行npm start时,会出现同样的错误。
唯一的选择是删除ios build文件夹后在Android设备上运行。
错误

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"
  }
}

我已经删除了多次节点模块,做了一个全新的安装以及,但问题出现了每一次。

ars1skjm

ars1skjm1#

原因是我有两个不同的package.json文件,它们的name属性值相同。

6yoyoihd

6yoyoihd2#

因为你的项目中有两个package.json文件,比如package.jsonanother\\package.json,它们都在一个子目录中。你也可以在终端上获得更多的信息,大多数时候,它包含路径:

您只需删除子目录Not Main file中的重复文件。

xt0899hw

xt0899hw3#

我已经把node_module的备份作为“xnode_module”放回了项目根目录中。所以我已经删除了备份,它对我很有效。

zzzyeukh

zzzyeukh4#

cd ios/
rm -rf build/
xcodebuild clean
cd ..
react native run ios

或检查项目内部,您必须在其中具有相同名称项目

fdx2calv

fdx2calv5#

这个步骤为我解决了。
关闭模拟器和Xcode,然后运行此命令。

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
uurity8g

uurity8g6#

在我的例子中,我在错误的项目中运行了npx react-native start。所以请确保您在正确的项目中。

cuxqih21

cuxqih217#

您可能对2个package.json文件使用了相同的名称。请对package.json文件使用不同的名称。

t3psigkw

t3psigkw8#

我有同样的问题,在我的情况下,原来它读2节点模块文件夹,即使我已经重命名了旧文件夹的东西

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'
}```

相关问题