React Native Metro Bundler遇到内部错误,请检查您的终端错误输出以获取更多详细信息

rqqzpn5f  于 2023-03-31  发布在  React
关注(0)|答案(7)|浏览(241)

当我说react-native run-android im getting below error.

Metro Bundler has encountered an internal error, please check your terminal error output for more details

下面是我的项目中的package.json。

{
    "name": "NCAPRNRedux",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "start": "node node_modules/react-native/local-cli/cli.js start",
        "test": "jest"
    },
    "dependencies": {
        "react": "16.2.0",
        "react-native": "0.52.2",
        "react-native-vector-icons": "^4.0.0",
        "react-navigation": "^1.0.0-beta.29",
        "react-redux": "^5.0.6",
        "redux": "^3.7.2",
        "redux-thunk": "^2.2.0"
    },
    "devDependencies": {
        "babel-jest": "22.1.0",
        "babel-plugin-transform-decorators-legacy": "^1.3.4",
        "babel-preset-react-native": "^4.0.0",
        "jest": "22.1.4",
        "react-test-renderer": "16.2.0"
    },
    "jest": {
        "preset": "react-native"
    }
}

有人遇到过这个问题并解决了吗?

prdp8dxp

prdp8dxp1#

你有没有这样的图片:
require("../assets/user.png")
如果是,请检查图像路径。我也遇到了同样的问题,所以我只是更正了路径,错误就消失了。

hc2pp10m

hc2pp10m2#

1.我建议重启React。只需运行以下命令:

# Kill current processes
killall node -9 

# Start React - Native
react-native start 

# Run android
react-native run-android or  react-native run-ios

应该可以了。
2.如果它不起作用,请检查您使用的图像路径。例如

<Image 
  source={require("./images/logo.png")} // check your image path you have used
>
jdzmm42g

jdzmm42g3#

运行这些命令

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

还有这个命令

rm ./node_modules/react-native/local-cli/core/__fixtures__/files/package.json

然后运行

npm i && react-native run-android

或run-ios任何适用的东西

jmo0nnb3

jmo0nnb34#

我遇到了这个问题,这就是我如何解决它。
如果你确定你的代码没有任何问题,你可以尝试在端口8081重新启动进程。
打开你的终端,用下面的命令找到进程ID:

sudo lsof -n -i :8081 | grep LISTEN

然后使用kill id,其中idlsof返回
之后,只需运行您的应用程序

react-native run-android
vmpqdwk3

vmpqdwk35#

尝试删除"react-native-vector-icons": "^4.0.0"
此问题可能会帮助您找到可能的解决方案

vshtjzan

vshtjzan6#

我也遇到过同样的问题。在我的情况下,基本上是因为导入语句中的一些错误路径。在纠正所有导入路径(即样式,组件,路由器,还原器,动作等),重新启动模拟器并再次运行构建后,问题得到解决。

ct2axkht

ct2axkht7#

这可能是metro.config.js文件的内容。我遇到了这个问题,我改变了节点版本并做了其他操作,但我的问题没有解决,所以我改变了metro.config文件,然后修复了这个错误。
metro.config.js内容:

/**
 * Metro configuration for React Native
 * https://github.com/facebook/react-native
 *
 * @format
 */

module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: true,
      },
    }),
  },
};

相关问题