错误:绑定失败:TypeError:Cannot read property 'transformFile' of undefined,React Native

zf2sa74q  于 2023-03-24  发布在  React
关注(0)|答案(9)|浏览(141)

每当我运行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)

这是我的包。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",
    "react-native-restart": "0.0.14",
    "react-native-shadow": "^1.2.2",
    "react-native-svg": "12.0.3",
    "react-native-vector-icons": "6.6.0",
    "react-native-web": "^0.9.13",
    "react-navigation": "4.0.10",
    "react-navigation-drawer": "2.3.3",
    "react-navigation-stack": "1.10.3",
    "stripe": "^8.33.0",
    "tipsi-stripe": "7.5.1",
    "typescript": "^3.8.3"
  },
  "devDependencies": {
    "@babel/core": "7.7.4",
    "@babel/runtime": "7.7.4",
    "@react-native-community/eslint-config": "0.0.5",
    "babel-jest": "24.9.0",
    "eslint": "^5.0.0",
    "jest": "24.9.0",
    "metro-react-native-babel-preset": "0.56.3",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

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

myzjeezk

myzjeezk1#

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

z9ju0rcb

z9ju0rcb2#

第一条评论中的解决方案对我来说很有效,那就是删除node_modules和package-lock.json,但是,我不想这样做,因为我知道我会遇到更多的错误,当然我做到了,但至少我能够修复它们并让它运行,不像我问的顽固错误。所以,是的,这个方法有效,但我绝对希望有人有更好的方法。

rkue9o1l

rkue9o1l3#

我遇到了这个错误。我做了两件事,我认为这导致我修复了这个问题:

  • 我在一个monorepo中工作,所以我将以下代码添加到我的package.json中:
"workspaces": {
    "nohoist": [
        "react-native",
        "react-native/**",
        "react",
        "react/**"
    ]
}
  • 我将我的metro-react-native-babel-preset包从^0.58.0升级到最新版本-^0.59.0yarn add -D metro-react-native-babel-preset
70gysomp

70gysomp4#

我在Nodejs版本17.1.0也有同样的问题。只需卸载它并重新安装Nodejs版本16.13.0。

kmbjn2e3

kmbjn2e35#

我也遇到了同样的问题。我运行的是npm v7.和node v10。我把两者都升级到了最新版本,它开始工作了。

vshtjzan

vshtjzan6#

当我在metro配置中使用inline require进行性能优化时,发生了这个错误。
我将metro配置属性“blacklist”更改为“blockList”来解决这个问题:

return {
    preloadedModules: moduleMap,
    transform: { inlineRequires: { blockList: moduleMap } },
  }
wfypjpf4

wfypjpf47#

这是一个旧的线程,但我想贡献,因为它是第一个出现在谷歌搜索“无法读取属性'transformFile'的未定义”的线程之一。
这可能不是一个永久的修复,因为它似乎突然出现在安装新的依赖项时,我也使用博览会。
为了解决这个问题,我已经安装了依赖项,然后使用yarn-upgrade-all来遍历你的 package.json 并将它们升级到最新版本。这显然会导致冲突,但对我来说,它是有效的(到目前为止),不需要像删除文件夹或文件这样的激烈操作。

wj8zmpe1

wj8zmpe18#

rm -rf node_modules
yarn
pod install
9cbw7uwe

9cbw7uwe9#

将节点降级到版本14即可修复

相关问题