错误:捆绑失败:TypeError:无法读取未定义的属性“transformFile”

每当我运行 react-native start 时都会收到此错误,但最近在我的节点模块中安装了 firebase-tools 和 stripe 后开始发生此错误,但在此之前它会运行得很好,这也是错误的堆栈跟踪:


::ffff:127.0.0.1 - - [22/Mar/2020:19:59:30 +0000] "GET /index.bundle?platform=android&dev=true&minify=false HTTP/1.1" 500 - "-" "okhttp/3.12.1"

error: bundling failed: TypeError: Cannot read property 'transformFile' of undefined

    at C:\Users\me\Project\node_modules\react-native\node_modules\@react-native-community\cli\node_modules\metro\src\Bundler.js:87:34

    at Generator.next (<anonymous>)

    at asyncGeneratorStep (C:\Users\me\Project\node_modules\react-native\node_modules\@react-native-community\cli\node_modules\metro\src\Bundler.js:14:24)

    at _next (C:\Users\me\Project\node_modules\react-native\node_modules\@react-native-community\cli\node_modules\metro\src\Bundler.js:34:9)

    at processTicksAndRejections (internal/process/task_queues.js:93:5)

这是我的 package.json:


{

  "name": "Project",

  "version": "0.0.1",

  "private": true,

  "scripts": {

    "android": "react-native run-android",

    "ios": "react-native run-ios",

    "start": "react-native start",

    "test": "jest",

    "lint": "eslint ."

  },

  "dependencies": {

    "card-validator": "6.2.0",

    "firebase-tools": "7.15.1",

    "jetifier": "^1.6.5",

    "prop-types": "15.7.2",

    "react": "^16.13.1",

    "react-art": "^16.13.1",

    "react-dom": "^16.13.1",

    "react-geocode": "0.2.1",

    "react-native": "0.61.5",

    "react-native-country-picker-modal": "1.9.8",

    "react-native-elements": "1.2.7",

    "react-native-firebase": "5.6.0",

    "react-native-geocoding": "0.4.0",

    "react-native-gesture-handler": "1.5.2",

    "react-native-maps": "0.26.1",

    "react-native-paper": "3.2.1",

    "react-native-reanimated": "1.4.0",

  },

很清楚另一个在 StackOverflow 上存在相同问题的问题,但该问题的解决方案对我不起作用,因为当我运行 react-native start 时 npm 忽略了它,因为这些模块已被弃用,我仍然得到相同错误


回首忆惘然
浏览 217回答 3
3回答

天涯尽头无女友

将 NodeJS 降级到 LTS 版本总是有帮助的。我在尝试使用 NodeJS^17 时遇到了同样的问题,但是当我将其降级到 NodeJS^14 并重新安装 node_modules 时,一切都已修复。

蝴蝶刀刀

问题下第一条评论中的解决方案对我有用,它删除了 node_modules 和 package-lock.json,但是,我不想这样做,因为我知道我会遇到更多错误,而且我确实做到了,但是至少我能够修复它们并让它运行,这与我询问的顽固错误不同。所以是的,这种方法有效,但我绝对希望有人有更好的方法。

POPMUISE

我遇到了这个错误。我做了两件事,我认为这导致我解决了这个问题:我在 monorepo 工作,所以我将以下代码添加到我的package.json:"workspaces": {&nbsp; &nbsp; "nohoist": [&nbsp; &nbsp; &nbsp; &nbsp; "react-native",&nbsp; &nbsp; &nbsp; &nbsp; "react-native/**",&nbsp; &nbsp; &nbsp; &nbsp; "react",&nbsp; &nbsp; &nbsp; &nbsp; "react/**"&nbsp; &nbsp; ]}我将我的metro-react-native-babel-preset包从升级^0.58.0到最新版本 - ^0.59.0( yarn add -D metro-react-native-babel-preset)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript