create-react-app运行报错“Module not found” 无法创建项目问题求助
解决方案
- 首先卸载全局安装的create-react-app,官方已不推荐全局安装的使用方式,旧版本全局包会与新的依赖逻辑产生冲突:
npm uninstall -g create-react-app - 使用官方推荐的npx方式拉取最新版脚手架创建项目,避免本地旧版本缓存影响:
npx create-react-app@latest 你的项目名称 - 如果你使用的是Node 17及以上版本,Node自带的OpenSSL 3.0与旧版本脚手架存在兼容问题,可以在创建命令前添加兼容参数再执行:
- Windows cmd环境:
set NODE_OPTIONS=--openssl-legacy-provider && npx create-react-app@latest 你的项目名称 - Windows PowerShell环境:
$env:NODE_OPTIONS="--openssl-legacy-provider"; npx create-react-app@latest 你的项目名称 - Mac/Linux环境:
NODE_OPTIONS=--openssl-legacy-provider npx create-react-app@latest 你的项目名称
- Windows cmd环境:
- 若上述操作仍报错,大概率是网络原因导致依赖包下载不完整,可以临时切换国内镜像源创建项目:
npx create-react-app@latest 你的项目名称 --registry https://registry.npmmirror.com - 如果你之前卸载重装Node时没有清理残留文件,可以手动删除当前用户目录下的
npm、npm-cache文件夹(Windows系统路径为C:\Users\你的用户名\AppData\Roaming\,Mac/Linux为~/.npm/)后再次尝试。 - 仍有问题可以换用pnpm创建项目:
npm install -g pnpm pnpm create react-app 你的项目名称
内容的提问来源于stack exchange,提问作者Bharat Pippal
相关产品推荐
相关产品推荐

