创建react项目时遇到的报错
百度到的第一个方法:
1.执行npm install -g create-react-app全局安装
2.执行npx create-react-app myapp创建项目
结果控制台打印:
(node:18924) ExperimentalWarning: The fs.promises API is experimental
You are running `create-react-app` 4.0.1, which is behind the latest release (4.0.2).
We no longer support global installation of Create React App.
Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app
The latest instructions for creating a new app can be found here:
https://create-react-app.dev/docs/getting-started/
之后尝试第二种方法(操作之前升级了一下npm到最新版本):
1.使用npm自带的create-react-app,不再全局使用全局安装的,第一步卸载之前(npm install -g create-react-app)下载的全局依赖,执行npm uninstall -g create-react-app
2.执行npx create-react-app myapp期待结果正确安装
结果控制台打印:
(node:19452) ExperimentalWarning: The fs.promises API is experimental
You are running `create-react-app` 4.0.1, which is behind the latest release (4.0.2).
We no longer support global installation of Create React App.
Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app
The latest instructions for creating a new app can be found here:
https://create-react-app.dev/docs/getting-started/
npm ERR! code 1
npm ERR! path E:\xxx\react
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c create-react-app myapp
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\xxx\AppData\Local\npm-cache\_logs\2021-02-04T01_25_30_719Z-
仍然不好用,寻找第三种解决方案
1.设置npm镜像库(之前设置成公司的镜像库了)执行npm config set registry https://registry.npm.taobao.org
2.执行npx create-react-app myapp创建项目
结果:安装成功
Success! Created myapp at E:\xxx\react\myapp
Inside that directory, you can run several commands:
npm start
Starts the development server.
npm run build
Bundles the app into static files for production.
npm test
Starts the test runner.
npm run eject
Removes this tool and copies build dependencies, configuration files
and scripts into the app directory. If you do this, you can’t go back!
We suggest that you begin by typing:
cd myapp
npm start
Happy hacking!
网友评论