create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Can't create react app with npx or yarn

Open Tobi-davies opened this issue 3 years ago • 4 comments

I am unable to create new react projects with npx or yarn. I'm also unable to install necessary dependency packages into existing react projects. I got this error:

$ npx create-react-app new-fr

Creating a new React app in C:\Users\HP\Desktop\side-projects\fresh\new-fr.

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

npm ERR! code UNKNOWN npm ERR! syscall mkdir npm ERR! path C:\Users\HP\AppData\Local\npm-cache_cacache\index-v5\ab\02 npm ERR! errno UNKNOWN npm ERR! Invalid response body while trying to fetch https://registry.npmjs.org/@babel%2fplugin-transform-react-jsx: UNKNOWN: unknown error, mkdir 'C:\Users\HP\AppData\Local\npm-cache_cacache\index-v5\ab\02'

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\HP\AppData\Local\npm-cache_logs\2022-07-16T09_58_49_000Z-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 new-fr/ from C:\Users\HP\Desktop\side-projects\fresh Done.

Tobi-davies avatar Jul 16 '22 10:07 Tobi-davies

Have you tried running an elevated command prompt?

Press Windows+R to open the “Run” box. Type “cmd” into the box and then press Ctrl+Shift+Enter to run the command as an administrator. Confirm by checking the title of the command prompt.

Now try running CRA. If you're still having issues, could you possibly look through the log file the error refers to to see if there's more details?

colaflaske avatar Jul 17 '22 23:07 colaflaske

Create-react-app is an outdated solution for creating react apps. Just use the vite and run: npm init vite Then, select the react template

Kenramiscal1106 avatar Aug 02 '22 05:08 Kenramiscal1106

Have you tried running an elevated command prompt?

Press Windows+R to open the “Run” box. Type “cmd” into the box and then press Ctrl+Shift+Enter to run the command as an administrator. Confirm by checking the title of the command prompt.

Now try running CRA. If you're still having issues, could you possibly look through the log file the error refers to to see if there's more details?

I have tried this and I still have the same issue. I have also tried to clear npm cache, but the cache wont clear

Tobi-davies avatar Aug 07 '22 12:08 Tobi-davies

follow this steps: 1- Check if your node and yarn is up to date if not, just update it. 2- If you've previously installed create-react-app globally via npm using install -g create-react-app, it is recommended by react docs to uninstall the package using npm uninstall -g create-react-app or yarn global remove create-react-app to ensure that npx always uses the latest version ( you can check globally install packages using npm list -g). 3-Clear/Clean your npm and yarn ( yarn cache clean or npm cache clean –force respectively ). 4-Then try npx create-react-app new-fr again. Hope it might help.

nthadrien avatar Sep 26 '22 14:09 nthadrien