I am having problems with npx create-react-app involving global installs. My confusion arises because as far as I'm aware the create-react-app package is not installed on my machine.
Some Details:
I start a react project (with typescript template) as I have previously and recently done on this same machine a number of times:
npx create-react-app --template typescript .
I get this prompt from the terminal
Need to install the following packages: create-react-app Ok to proceed? (y)
I press y to confirm it's okay to proceed. (If I press n, the process terminates with the following error: npm ERR! canceled.) The terminal then displays the following message
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.
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/
I run both suggested commands to uninstall create-react-app globally. npm goes smoothly:
npm uninstall -g create-react-app
up to date, audited 1 package in 179ms
found 0 vulnerabilities
the global yarn uninstall results with the following message:
remove create-react-app
yarn global v1.22.17
warning package.json: No license field
[1/2] 🗑 Removing module create-react-app...
error This module isn't specified in a package.json file.
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.
Finally I try to find if create-react-app exists on my machine with
which create-react-app
which results in
create-react-app not found.
I'm not sure how else to address this issue.
Edit: Solution provided by Deepthi and Sators. I had to clear the npx cache which had stored an older version of create-react-app by using command:
npx clear-npx-cache
Run npx clear-npx-cache
Why?
You already tried to create a react project using create-react-app before.
So there is an old version of create-react-app in the npx cache.
/user/.npm/_npx
npm uninstall -g create-react-app won't work for this case.
If you run npx clear-npx-cache it will remove all the caches in the directory /user/.npm/_npx
Now you can create react app using npx create-react-app my_app
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.
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/
Yes it appears as is as it is above.
Run some of these two options:
npm uninstall -g create-react-app
OR
yarn global remove create-react-app
Finally try again with npx command create-react-app
In my case, I use the one from npm unistall, finally run the command npx create-react-app again there if I started to create React project.
Run ---> npx clear-npx-cache
----> npx create-react-app your-app
You can try to locate the installed version by running:
npm ls -g create-react-app
You may also want to consider reading this post for removing/clearing the npx cache by using:
npx clear-npx-cache
Finally, another option is to ensure you are using the latest version of create-react-app by running:
npx create-react-app@latest --template typescript .
The problem here is that the npx create-react-app is trying to install packages from an older version (4.0.3) while the latest version is (5.0.0).
You can simply clear the npx cache by using the following command:
npx clear-npx-cache
and then try to create a react app again using
npx create-react-app Your_project_name
Or
You can use npx with @latest to guarantee that you are running create-react-app along with the latest version:
npx create-react-app@latest Your_project_name
Or
you can install the latest react app modules locally in the working directory by using:
npm install create-react-app@latest
(This will create react modules in addition to package.json and package-lock.json in the working directory which will be depended on when installing the react app, so you can delete them after finishing the next step)
and then:
npx create-react-app Your_project_name
Apparently there is a problem with that version, I just have the same issue, but with the command
npx clear-npx-cache
It did the trick, then I've just run the
npx create-react-app proyect-name
And it works!
I think this is the same answer as above, but well, there you go.
For something like this encountered:
" You are running create-react-app 4.0.3, which is behind the latest release (5.0.0)."
Solution was :
:> npx clear-npx-cache
Then do: :> npx create-react-app your-app
if you've tried everything above and no success.
Run:
npm audit fix --force
Then:
npx create-react-app <app
I had this same issue and it was happening because I was using nvm to manage node versions and I was running an older node version (12.14.1) for a client project. Using node v14.x.x solved the issue for me.