创建新的react应用时(npx create-react-app my-app)报错:You are running `create-react-app` 4.0.3, which is

姚宪
2023-12-01

创建新的react应用时(npx create-react-app my-app)报错

PS D:\WorkSpace\codeFiles> npx create-react-app my-app

You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.1).

We no longer support global installation of Create React App.

Please remove any global installs with one of the following commands:
- 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/

解决报错,并重新创建新项目

PS D:\WorkSpace\codeFiles> npm cache clean -f
npm WARN using --force I sure hope you know what you are doing.

PS D:\WorkSpace\codeFiles> npm cache verify
Cache verified and compressed (~\AppData\Roaming\npm-cache\_cacache):
Content verified: 0 (0 bytes)
Index entries: 0
Finished in 0.023s

PS D:\WorkSpace\codeFiles> npx clear-npx-cache  // 清除npx缓存
npx: 1 安装成功,用时 7.78 秒

PS D:\WorkSpace\codeFiles> npx create-react-app@latest my-app --use-npm
npx: 67 安装成功,用时 7.627 秒
Creating a new React app in /Users/yanmeisheng/vstest/view-performancen.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...
> core-js@3.25.5 postinstall /Users/yanmeisheng/vstest/view-performancen/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
> core-js-pure@3.25.5 postinstall /Users/yanmeisheng/vstest/view-performancen/node_modules/core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"
+ cra-template@1.2.0
+ react@18.2.0
+ react-scripts@5.0.1
+ react-dom@18.2.0
added 1413 packages from 628 contributors in 104.874s
217 packages are looking for funding
  run `npm fund` for details
Initialized a git repository.

Installing template dependencies using npm...
+ @testing-library/jest-dom@5.16.5
+ web-vitals@2.1.4
+ @testing-library/react@13.4.0
+ @testing-library/user-event@13.5.0
added 56 packages from 79 contributors in 14.095s

217 packages are looking for funding
  run `npm fund` for details

Removing template package using npm...

217 packages are looking for funding
  run `npm fund` for details
Created git commit.

Success! Created view-performancen at /Users/yanmeisheng/vstest/view-performancen
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 view-performancen
  npm start

Happy hacking!

⚠注意:

当执行 npm cache clean -f / npm cache clean --force 报以下错误时,是因为npm版本过高!
安装低版本npm–>> npm install npm@6.14.11 -g

PS D:\WorkSpace\codeFiles> npm cache clean -f                       
npm WARN using --force Recommended protections disabled.

PS D:\WorkSpace\codeFiles> npm install npm@6.14.11 -g

PS D:\WorkSpace\codeFiles> npm cache clean -f
npm WARN using --force I sure hope you know what you are doing.
 类似资料: