开发者问题收集

运行 react-native run-ios 时出错。错误:找不到模块“metro-config”

2019-07-24
35691

我正在使用 react-native run-is 命令通过终端运行 React-native 项目。我想在模拟器中运行它。首先我运行 npm install,然后运行 ​​react-native run-ios。它显示错误

Error: Cannot find module 'metro-config' Require stack: - /Users/tribond/Projects/JustHelper/justhelper2/node_modules/react-native/local-cli/util/Config.js - /Users/tribond/Projects/JustHelper/justhelper2/node_modules/react-native/local-cli/core/index.js - /Users/tribond/Projects/JustHelper/justhelper2/node_modules/react-native/local-cli/cliEntry.js - /Users/tribond/Projects/JustHelper/justhelper2/node_modules/react-native/local-cli/cli.js - /Users/tribond/Projects/JustHelper/justhelper2/node_modules/react-native/cli.js - /usr/local/lib/node_modules/react-native-cli/index.js

3个回答

您似乎没有安装 Metro-config 模块。请安装此模块。

npm i metro-config --save-dev
hong developer
2019-07-24

React Native 0.72 消息的屏幕截图

metro-config.js 添加到您的根项目文件夹并添加以下内容:

const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
const config = {};
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
hamza ahmad
2023-07-06

Latest React Native

根据最新的 react-native 文档,您必须更新 metro config 的开发依赖项。

我已使用 更新助手 react-native 迁移到 72.4 ,请严格遵循指南和文件更改日志,以避免任何遗漏

"devDependencies": {
  ...,
  "@react-native/metro-config": "^0.72.11",

 }

Older version of react-native

检查您的 metro-config 开发依赖项

npm i metro-config --save-dev
Sagar
2023-12-19