错误:在尝试npx react-native@latest init时找不到模块“has-flag”

rqdpfwrv  于 2023-08-07  发布在  React
关注(0)|答案(1)|浏览(126)

当尝试npx react-native@latest init AppTest时,我遇到了此错误:

node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'has-flag'
Require stack:
- C:\Users\Wiktor\AppData\Local\npm-cache\_npx\dea611a43221eddd\node_modules\supports-color\index.js
- C:\Users\Wiktor\AppData\Local\npm-cache\_npx\dea611a43221eddd\node_modules\chalk\source\index.js
- C:\Users\Wiktor\AppData\Local\npm-cache\_npx\dea611a43221eddd\node_modules\@react-native-community\cli-doctor\build\tools\healthchecks\androidHomeEnvVariable.js
- C:\Users\Wiktor\AppData\Local\npm-cache\_npx\dea611a43221eddd\node_modules\@react-native-community\cli-doctor\build\tools\healthchecks\index.js
- C:\Users\Wiktor\AppData\Local\npm-cache\_npx\dea611a43221eddd\node_modules\@react-native-community\cli-doctor\build\commands\doctor.js
- C:\Users\Wiktor\AppData\Local\npm-cache\_npx\dea611a43221eddd\node_modules\@react-native-community\cli-doctor\build\index.js
- C:\Users\Wiktor\AppData\Local\npm-cache\_npx\dea611a43221eddd\node_modules\@react-native-community\cli\build\bin.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\Wiktor\AppData\Local\npm-cache\_npx\dea611a43221eddd\node_modules\supports-color\index.js:4:17)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'MODULE_NOT_FOUND'

字符串
我做的第一件事就是用npm install -g has-flag安装丢失的软件包
测试结果:

npm install -g has-flag

changed 1 package in 667ms

1 package is looking for funding
  run `npm fund` for details


然后尝试npx react-native@latest init AppTest,但我得到相同的错误
有什么办法吗?

wwtsj6pe

wwtsj6pe1#

通过运行以下命令修复:npm i react-native@latest -g,然后是npx react-native init myProject

相关问题