Can't create react app with npx or yarn
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.
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?
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
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
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.