当我运行“npx react-native start”时找不到模块“@expo/metro-config”
Posted
技术标签:
【中文标题】当我运行“npx react-native start”时找不到模块“@expo/metro-config”【英文标题】:Cannot find module '@expo/metro-config' when i run "npx react-native start 【发布时间】:2021-07-10 21:57:13 【问题描述】:我正在尝试运行命令“npx react-native start”并显示此错误
error Cannot find module '@expo/metro-config'
Require stack:
- D:\Projetos\apporto\metro.config.js
- D:\Projetos\apporto\node_modules\cosmiconfig\node_modules\import-fresh\index.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\loaders.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\createExplorer.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\tools\config\readConfigFromDisk.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\tools\config\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\commands\install\install.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\commands\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\bin.js
Error: Cannot find module '@expo/metro-config'
Require stack:
- D:\Projetos\apporto\metro.config.js
- D:\Projetos\apporto\node_modules\cosmiconfig\node_modules\import-fresh\index.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\loaders.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\createExplorer.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\tools\config\readConfigFromDisk.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\tools\config\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\commands\install\install.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\commands\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\bin.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (D:\Projetos\apporto\metro.config.js:1:30)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:996:19)
我尝试使用npm i metro-config --save-dev
,但不起作用。
我不知道该怎么办。
###################package.json ######################## #######
“名称”:“批准”, “版本”:“0.0.1”, “私人”:真的, “脚本”: "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", “测试”:“开玩笑”, “lint”:“eslint”。 , “依赖”: "@react-native-community/async-storage": "^1.12.1", "@react-native-community/geolocation": "^2.0.2", "@react-native-community/masked-view": "^0.1.10", "@react-navigation/bottom-tabs": "^5.11.9", "@react-navigation/native": "^5.9.4", "@react-navigation/stack": "^5.14.4", “反应”:“17.0.1”, “反应原生”:“0.64.0”, "react-native-gesture-handler": "^1.10.3", "react-native-permissions": "^3.0.1", "react-native-reanimated": "^2.1.0", "react-native-safe-area-context": "^3.2.0", “反应原生屏幕”:“^3.1.1”, “react-native-svg”:“*”, “react-native-svg-transformer”:“^0.14.3”, "react-native-swiper": "^1.6.0", “样式化组件”:“^5.2.3” , “开发依赖”: "@babel/core": "^7.12.9", "@babel/runtime": "^7.12.5", "@react-native-community/eslint-config": "^2.0.0", "babel-jest": "^26.6.3", “eslint”:“7.14.0”, "笑话": "^26.6.3", “地铁配置”:“^0.64.0”, "metro-react-native-babel-preset": "^0.64.0", “反应测试渲染器”:“17.0.1” , “开玩笑”: “预设”:“反应原生”
【问题讨论】:
请发布您的package.json
文件内容
为什么不直接编辑问题并将其添加到那里?
@CornelRaiu 抱歉,这是我第一次在这里使用。
【参考方案1】:
安装 expo/metro-config 后:
npm i @expo/metro-config
转到 metro.config.js 更改:
const getDefaultConfig = require('expo/metro-config');
收件人:
const getDefaultConfig = require('@expo/metro-config');
它对我有用。 谢谢
【讨论】:
【参考方案2】:我遇到了同样的问题,我下载了 expo metro 配置并解决了问题
npm i @expo/metro-config
【讨论】:
【参考方案3】:这里缺少 expo 配置文件。 运行
npm i @expo/metro-config
在主文件夹中更新
metro.config.js
更改以下行
const getDefaultConfig = require('expo/metro-config');
到
const getDefaultConfig = require('@expo/metro-config');
像魅力一样工作!
【讨论】:
【参考方案4】:“名称”:“地铁配置”, “版本”:“0.64.0”, "description": "? Metro 配置解析器。", "main": "src/index.js", “存储库”: “类型”:“git”, “网址”:“git@github.com:facebook/metro.git” , “脚本”: "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", "cleanup-release": "test !-e build && mv src build && mv src.real src" , “许可证”:“麻省理工学院”, “依赖”: "cosmiconfig": "^5.0.5", “开玩笑验证”:“^26.5.2”, “地铁”:“0.64.0”, “地铁缓存”:“0.64.0”, “地铁核心”:“0.64.0”, “地铁运行时”:“0.64.0” , “devDependencies”: "漂亮格式": "^26.5.2", "strip-ansi": "^6.0.0"
【讨论】:
以上是关于当我运行“npx react-native start”时找不到模块“@expo/metro-config”的主要内容,如果未能解决你的问题,请参考以下文章
当我在 Eclipse 中运行 hadoop 作业时出现异常
当我的应用程序无法在调试模式下运行,但 exe 文件可以正常运行时,这意味着啥?
当我从 SQL Server 代理运行 Python 脚本时,为啥它会失败?
当我从 PyCharm 运行代码时,我看到一个空白的 GUI [重复]