1、安装方式
1)npx create-react-app 项目名称
npx的工作原理是首先在当前项目的./node_modules/.bin路径下查找要执行的包,如果找不到,它会检查全局是否已安装对应的模块。如果全局也没有,npx会自动下载对应的模块到一个临时目录,并在执行完毕后删除,这样就不会长期占用本地资源。
2)①先全局安装 cnpm install -g create-react-app
②再创建项目 create-react-app 项目名称
2、删除全局安装的create-react-app
1)获取路径npm root -g
2)进入目录:cd 路径
3)查看都安装了什么:ls
4)移除:npm uninstall -g create-react-app
3、淘宝镜像报错
1)查看镜像:npm config get registry
2)重新设置镜像:npm config set registry https://registry.npmmirror.com
4、安装之后立即报错
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
不能解析依赖树 ,需要先修复上面依赖关系冲突或者重新执行一下npm install命令
image.png
解决办法:cnpm install --legacy-peer-deps
5、启动报错
image.png
解决办法:cnpm install web-vitals
6、运行报错
One of your dependencies, babel-preset-react-app, is importing the
"@babel/plugin-proposal-private-property-in-object" package without
declaring it in its dependencies. This is currently working because
"@babel/plugin-proposal-private-property-in-object" is already in your
node_modules folder for unrelated reasons, but it may break at any time.
babel-preset-react-app is part of the create-react-app project, which
is not maintianed anymore. It is thus unlikely that this bug will
ever be fixed. Add "@babel/plugin-proposal-private-property-in-object" to
your devDependencies to work around this error. This will make this message
go away.
image.png
解决办法:
cnpm install --save-dev @babel/plugin-proposal-private-property-in-object