简体   繁体   中英

Error when I run npx create-react-app my-app

I have tried these two commands and am getting the same error.

npm clean cache --force
npx create-react-app client -timeout=120000


$ npx create-react-app client -timeout=120000
npm WARN exec The following package was not found and will be installed: create-react-app
npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.

Creating a new React app in C:\web_dev\MERN\projects\booking-app\client.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

npm ERR! code ERR_SOCKET_TIMEOUT
npm ERR! errno ERR_SOCKET_TIMEOUT
npm ERR! network request to https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz failed, reason: Socket timeout
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\web_dev\MERN\projects\booking-app\tmpnodejsnpm-cache\_logs\2021-12-29T13_37_03_989Z-debug-0.log

Aborting installation.
  npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.

Deleting generated file... package.json
Deleting client/ from C:\web_dev\MERN\projects\booking-app
Done.

Have you tried what the error said

a)Are you online

b)Are you behind a proxy or a vpn

c)have you configured the logs properly

id like a bit more context like your os and stuff

I had the same problem so I uninstalled it globally then reinstall:-

  • npm uninstall -g create-react-app
  • npm uninstall create-react-app

Then I used npx:-

  • npx create-react-app project-app

Tell me if this works for you

Try this:

npm install -g npm@latest
npm install node
npm install -g yarn
yarn cache clean
npx create-react-app my-app

I have just faced the same issue when upgrading an old project. What solved, in my case was:

  • If you use yarn :
yarn global remove create-react-app
yarn cache clean
  • If you use npm :
npm remove create-react-app
npx clear-npx-cache

Also make sure there is no folder in the directory where you will created the new React project because you can get another warning similar to:

The directory . contains files that could conflict:

  <the file(s) name here>/

Either try using a new directory name, or remove the files listed above.

After that, npx create-react-app. ran smoothly.

Those steps described above solved the following subsequent warnings (versions may vary).:

  1. Global warning
You are running "create-react-app" 4.0.3, which is behind the latest release (5.0.0).
We no longer support global installation of Create React App.
  1. tar warning
tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.

Even I was getting the same error and then saw your question I closed all the task and run this command "npx create-react-app my-app" again it got solved!

No...its not working for me what should I do now.... I'm trying since long time but still its not working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM