You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行npx react-native@latest init时出现has-flag模块找不到的问题

解决npx react-native init时"Cannot find module 'has-flag'"的问题

你遇到的问题是npx临时下载的react-native CLI缓存中依赖缺失,全局安装has-flag无法被npx的临时环境识别,以下是可行的解决方案:

方案1:清理npm缓存后重新尝试

执行命令清空npm本地缓存,让npx重新下载完整的依赖包:

npm cache clean --force

之后再次执行初始化命令:

npx react-native@latest init AppTest

方案2:全局安装react-native CLI后初始化

先全局安装完整的react-native社区CLI,避免npx临时环境的依赖问题:

npm install -g @react-native-community/cli

然后直接用全局CLI初始化项目:

react-native init AppTest

方案3:跳过CLI的doctor检查(应急方案)

错误触发自cli-doctor模块的依赖,初始化时跳过doctor检查可以直接完成项目创建:

npx react-native@latest init AppTest --skip doctor

内容的提问来源于stack exchange,提问作者NOKIEQU

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 06:30:59