电脑原先使用npm install -g create-react-app
命令全局安装过,根据文档先全局卸载npm uninstall -g create-react-app
,然后采用npx create-react-app my-app
创建项目。然而,项目创建完后,却只生成了node_modules
,package.json
,package_lock.json
或yarn.lock
这几个文件夹,同时报错:
解决
1、运行create-react-app -V
查看版本号,发现还可以拿到版本号,说明未被完全删除。
2、运行where create-react-app
命令,若是有返回内容,则将返回内容全部手动删除。在我的电脑上操作,返回了以下两个文件路径。
C:\\Users\\XXXX\\AppData\\Local\\Yarn\\config\\global\\node_modules\\.bin\\create- react-app C:\\Users\\XXXXX\\AppData\\Local\\Yarn\\config\\global\\node_modules\\.bin\\create- react-app.cmd
3、再次运行create-react-app -V
查看版本号,可看到
4、运行npx create-react-app my-app
命令。
问题
若是运行npx create-react-app my-app
命令,出现
npm ERR! code ENOLOCAL npm ERR! Could not install from "Files\\nodejs\\node_cache\\_npx\\18944" as it does not contain a package.json file.
根据
是因为安装node的路径中存在空格。我的node是安装在E:\\Program Files\\nodejs
,它并不识别Program Files
中的空格。
解决方法:
cmd开启dos窗口,运行
npm config set prefix "E:\\Program~1\\nodejs\\node_global" npm config set cache "E:\\Program~1\\nodejs\\node_cache"
参考自:
Template not provided using create-react-app
windows中node环境采坑
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
© 版权声明
THE END
暂无评论内容