在 ios sim 中运行 React-native 项目时出错。(找不到模块“@react-native/metro-config”)

Error Running React-native project in ios sim. (Cannot find module '@react-native/metro-config')

提问人:aireal59 提问时间:11/17/2023 更新时间:11/17/2023 访问量:9

问:

我正在尝试在 Xcode 模拟器中运行一个 react-native 的新项目。

如果我运行 ,我会收到以下错误:react-native run-ios

“'节点位于:/Users/lukearthur/.nvm/versions/node/v16.15.0/bin/node 错误:找不到模块“@react-native/metro-config” 需要堆栈:

  • /Users/lukearthur/Documents/clients/metro.config.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/[email protected]/node_modules/import-fresh/index.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/[email protected]/node_modules/cosmiconfig/dist/loaders.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/c[email protected]/node_modules/cosmiconfig/dist/createExplorer.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/[email protected]/node_modules/cosmiconfig/dist/index.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/@[email protected]/node_modules/@react-native-community/cli-config/build/readConfigFromDisk.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/@[email protected]/node_modules/@react-native-community/cli-config/build/loadConfig.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/@[email protected]/node_modules/@react-native-community/cli-config/build/index.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@react-native-community/cli/build/commands/index.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/@[email protected]_@babel+cor[email protected]/node_modules/@react-native-community/cli/build/index.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]/node_modules/react-native/cli.js。 错误:找不到模块“@react-native/metro-config” 需要堆栈:
  • /Users/lukearthur/Documents/clients/metro.config.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/[email protected]/node_modules/import-fresh/index.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/[email protected]/node_modules/cosmiconfig/dist/loaders.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/c[email protected]/node_modules/cosmiconfig/dist/createExplorer.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/[email protected]/node_modules/cosmiconfig/dist/index.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/@[email protected]/node_modules/@react-native-community/cli-config/build/readConfigFromDisk.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/@[email protected]/node_modules/@react-native-community/cli-config/build/loadConfig.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/@[email protected]/node_modules/@react-native-community/cli-config/build/index.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@react-native-community/cli/build/commands/index.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/@[email protected]_@babel+cor[email protected]/node_modules/@react-native-community/cli/build/index.js
  • /Users/lukearthur/Documents/clients/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]/node_modules/react-native/cli.js 在 Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) 在 Function.Module._load (node:internal/modules/cjs/loader:778:27) 在 Module.require (node:internal/modules/cjs/loader:1005:19) 在需要(节点:internal/modules/cjs/helpers:102:18) at 对象。(/Users/lukearthur/Documents/clients/metro.config.js:1:41) 在 Module._compile (node:internal/modules/cjs/loader:1105:14) 在Object.Module._extensions..js (节点:internal/modules/cjs/loader:1159:10) 在 Module.load (node:internal/modules/cjs/loader:981:32) 在 Function.Module._load (node:internal/modules/cjs/loader:822:12) 在 Module.require (node:internal/modules/cjs/loader:1005:19) 进程已终止。按下可关闭窗口'”

我的 react-native 位于单存储库“客户端”中。该项目位于“/Users/lukearthur/Documents/clients/apps/taskratchet-app”。

依赖项将提升到 .nvmrc 中的本地项目

  • 我的系统是运行 Sonoma 2 的 m14.1.1 macbook air

  • 我的 Xcode 目前是 beta 版本 15.1 beta 3。(这只是因为我怀疑另一个问题的 Xcode 问题,并下载了测试版以排除这种情况)

  • 我已经运行了全新安装的 .pnpm i

  • 我已经跑了npm install --save-dev @react-native-community/cli-tools

node.js react-native pnpm java-metro-framework xcode-command-line-tools

评论


答: 暂无答案