电脑原先使用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这几个文件夹,同时报错:npm install -g create-react-appnpm uninstall -g create-react-appnpx create-react-app my-appnode_modulespackage.jsonpackage_lock.jsonyarn.lock解决解决解决1、运行create-react-app -V查看版本号,发现还可以拿到版本号,说明未被完全删除。
2、运行where create-react-app命令,若是有返回内容,则将返回内容全部手动删除。在我的电脑上操作,返回了以下两个文件路径。create-react-app -Vwhere 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
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.cmd3、再次运行create-react-app -V查看版本号,可看到create-react-app -V
4、运行npx create-react-app my-app命令。npx create-react-app my-app问题问题问题若是运行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.
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中的空格。E:\Program Files\nodejsProgram Files解决方法:
cmd开启dos窗口,运行
npm config set prefix "E:\Program~1\nodejs\node_global"
npm config set cache "E:\Program~1\nodejs\node_cache"
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环境采坑Template not provided using create-react-appwindows中node环境采坑以上就是本文的全部内容,希望对大家的学习有所帮助。