facebook / create-react-app

Set up a modern web app by running one command.
https://create-react-app.dev
MIT License
102.72k stars 26.85k forks source link

We no longer support global installation of Create React App #12022

Open Arcanorum opened 2 years ago

Arcanorum commented 2 years ago

Describe the bug

I'm not comfortable with all of the critical bugs in the recently released CRA 5.0.0, so want to use the most recent reliable v4 instead, 4.0.3. Can't use npx create-react-app any more due to following error.

user:~/my-dir$ npx create-react-app@4.0.3 my-new-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/

npm version: 8.1.0

Steps to reproduce

Try creating a new react app using CRA.

Expected behavior

Should create a new CRA app. Should not care about latest release.

Actual behavior

Error.

theunderdogdev commented 2 years ago

It's not an error it's just a warning. Facebook suggests to use latest version of CRA for creating apps. Use this instead

npx create-react-app <your-app-name>

For more info refer to this stack overflow question

andy5090 commented 2 years ago

It's not an error it's just a warning. Facebook suggests to use latest version of CRA for creating apps. Use this instead

npx create-react-app <your-app-name>

For more info refer to this stack overflow question

You mean this one

npx create-react-app@latest <your-project-name>

I had a same problem and this has solved the problem. but should be working without designating version or latest in the future I hope.

codeeno commented 2 years ago

Is there a way to skip this error and force running a certain version of CRA instead of installing the latest one?

theunderdogdev commented 2 years ago

Then try this npm i -g create-react-app@<version>

Then in your folder where you want to create the application

create-react-app <app-name>

This should work

HansBrende commented 2 years ago

I got the same error even when doing simply:

npx create-react-app my-new-app

Then I tried:

npm uninstall -g create-react-app
npx create-react-app my-new-app

Same error again.

The only way I was able to get cra working at all was via the following command:

npx create-react-app@latest my-new-app  # only command that works now!

It's not an error it's just a warning.

False. It fails to "create a react app". Therefore, it is an error.

theunderdogdev commented 2 years ago

False. It fails to "create a react app". Therefore, it is an error.

Ok. I can’t verify myself coz I am running into other errors which are not very known to me. You have to wait for a developer of this package who might help you out.

Bwca commented 2 years ago

It won't work even if you install create-react-app as an npm package in a separate project and try to run it from there.

However there can be cases that require cra of versions lower than 5.x, i.e. when you attempt to migrate an application from custom webpack config to create-react-app and aiming for 5.x introduces significant breaking changes.

Please don't burn the bridges for those who can't jump to the latest 5.x cra :)

theunderdogdev commented 2 years ago

Please don't burn the bridges for those who can't jump to the latest 5.x cra :)

Haha agreed! There are a lot of changes in cra 5 and it’s buggy too

likeke1997 commented 2 years ago

try it? https://zhuanlan.zhihu.com/p/296542499 I'm not good in English, sui bian kan kan~

Steps:

# WINDOWS 10

# clone cra and checkout to old version
git clone https://github.com/facebook/create-react-app.git
cd ./create-react-app
git checkout -b v4.0.3 v4.0.3

# install lerna that cra needed, and run bootstrap
npm i -g lerna
lerna bootstrap

# npx create-react-app using old files
cd ../
npx create-react-app cra-project-old --scripts-version file:.\create-react-app\packages\react-scripts --template file:.\create-react-app\packages\cra-template-typescript

# edit dependencies and re-install
cd ./cra-project-old
# replace following:
#    "react": "^17.0.2",
#    "react-dom": "^17.0.2",
#    "react-scripts": "file:../create-react-app/packages/react-scripts",
# to it:
#     "react": "^16.12.0",
#     "react-dom": "^16.12.0",
#     "react-scripts": "^4.0.3",
rimraf node_modules
rimraf package-lock.json
npm i

# it's all right!
DylanSp commented 2 years ago

It looks from the source code that trying to use any version but the latest version errors out.

Maintainers: could we at least get an appropriate error message if the problem is trying to use an unsupported version? Or possibly allow installing with an older version of CRA, with a warning?

kthewhispers commented 2 years ago

It's not an error it's just a warning. Facebook suggests to use latest version of CRA for creating apps. Use this instead

npx create-react-app <your-app-name>

For more info refer to this stack overflow question

You mean this one

npx create-react-app@latest <your-project-name>

I had a same problem and this has solved the problem. but should be working without designating version or latest in the future I hope.

I'll definitely be typing npx create-react-app@latest my-app until they figure this out lol.

godmar commented 2 years ago

Seeing this as well. The instructions provided lead to an infinite loop.

HansBrende commented 2 years ago

Possibly related to: https://github.com/facebook/create-react-app/issues/10601 and https://github.com/npm/cli/issues/2329

Also helpful: npx clear-npx-cache (This fixed the issue for me: I no longer have to specify @latest to get the command to work.)

(Though, I guess this does not fix the original issue the OP was interested in, which was CRA not allowing a version prior to latest to work.)

rafalp commented 2 years ago

If nothing else works for you:

  1. Create new directory
  2. npm init in it (use w/e data you want, this is throw-away directory)
  3. npm install create-react-app@4.0.3
  4. In node_modules/create-react-app/createReactApp.js find line if (latest && semver.lt(packageJson.version, latest)) { and change it to if (false && latest && semver.lt(packageJson.version, latest)) {
  5. Add this line to your npm scripts: create-react-app my-app --template typescript --use-npm (customize what you need)
  6. run npm run setup
  7. enjoy
WayneEllery commented 2 years ago

My workaround is to install globally and use global version. This will use version v4 of create-react-app instead of v5 but it will install v5 of react-scripts so it will install the latest version for the created app

GioeleSalvioni commented 2 years ago

I solved this problem with this command:

npx clear-npx-cache

msikma commented 2 years ago

The readme really should be updated. Right now the website displays instructions that just don't work, or at least not for everybody.

juanmait commented 2 years ago

I solved this problem with this command:

npx clear-npx-cache

That worked for me. The documentation should suggest that you might need to clear the npx cache.

r0binxp commented 2 years ago
npx create-react-app@latest my-new-app

This Works for me, thanks

manutorre commented 2 years ago

If nothing else works for you:

  1. Create new directory
  2. npm init in it (use w/e data you want, this is throw-away directory)
  3. npm install create-react-app@4.0.3
  4. In node_modules/create-react-app/createReactApp.js find line if (latest && semver.lt(packageJson.version, latest)) { and change it to if (false && latest && semver.lt(packageJson.version, latest)) {
  5. Add this line to your npm scripts: create-react-app my-app --template typescript --use-npm (customize what you need)
  6. run npm run setup
  7. enjoy

Thanks man, this works. However, it's crazy that we need to do this to use an older version

menefrego15 commented 2 years ago

You should maybe try to do : npm init react-app my-app

It worked for me !

drey-rotation commented 2 years ago

Here is what works for me:

mkdir my-app cd my-app npm i create-react-app@5.0.1 npx create-react-app@5.0.1 .

You could probably use @latest instead of @5.0.1.

original001 commented 2 years ago

I think, that problem is deeper. There is no stable version in cra. We have only latest, but it's not stable. For example, I create app from latest and gave react 18. But storybook does not support react 18 yet. Storybook is commonly used, and it's not good just ignore that case. I don't think that is stable version, if I have to patch verisons in my final package.json.

Also I have my own template, that use my company. I'm very frustrating, when I cannot create new app. lastest cra break compatibility with common tools and have no possibility to install previous more stable version.

I suggest to support two versions - stable and latest. In that case maintainers don't have to support all possible versions of cra, but only two. If users of cra are getting errors with latest, they have stable version, that ok.

Stable version should support all common used tools like storybook by scratch.

adimshev commented 2 years ago

npx clear-npx-cache

ChittaMadhobi commented 2 years ago

If nothing else works for you:

  1. Create new directory
  2. npm init in it (use w/e data you want, this is throw-away directory)
  3. npm install create-react-app@4.0.3
  4. In node_modules/create-react-app/createReactApp.js find line if (latest && semver.lt(packageJson.version, latest)) { and change it to if (false && latest && semver.lt(packageJson.version, latest)) {
  5. Add this line to your npm scripts: create-react-app my-app --template typescript --use-npm (customize what you need)
  6. run npm run setup
  7. enjoy
ChittaMadhobi commented 2 years ago

This is the only way it worked. I tried to clear cache, install the latest create-react-app. As many commented before, the outcome is not just a warning. It does not create an app. Hence, this is a serious bug. Create-react-app should consider a quick response.

Nessvah commented 2 years ago

I tried every command and every suggestion here. nothing worked. It didn't provide any kind of template, not even with the template flag.

There is one thing that is working to get the template: npx create-react-app@latest <name of app>

I hope they will fix this soon.

SarmanAulakh commented 2 years ago

I got this issue too. I did what @adimshev said with clear cache and it worked. I was promted to install create-react-app@5.0.1 after clearing cache and running npx cra again. Now all subsequence npx create-react-apps also work fine!

$ npx create-react-app test
You are running `create-react-app` 5.0.0, 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:
- 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/
$ npx create-react-app --version
5.0.0
$ npx clear-npx-cache
Need to install the following packages:
  clear-npx-cache@1.0.1
Ok to proceed? (y) y
$ npx create-react-app test
Need to install the following packages:
  create-react-app@5.0.1
Ok to proceed? (y) y
raquelhortab commented 2 years ago

I am really getting tired of all the problems of CRA, and still it keeps surprising me. The latest version creates apps with react 18, which might be an issue for many reasons. And now they don't even allow using older versions? Or options to select the react version to use? This is simply absurd. I work in programming education and I am really going to consider switching to another approach, no more recommending students to use this.

paulhoule commented 1 year ago

I'll add to the chorus that this is completely uncool.

I received the same wrong error message following the wrong instructions that CRA publishes for "getting started". npx clear-npx-cache solved the problem. I had no, absolutely zero, packages installed globally with npm, I don't need to get gaslighted with incorrect error messages.

In this case I am putting together a toy application to debug a problem (not really React-related) with a large React application and CRA is potentially a big help if it can save time setting up. I guess for work I'd have to set the whole thing up manually with CRA and I probably would have, but if it was a side project I'd seriously think about ditching React for Svelte or somebody else who attends to having correct instructions for the most critical operation (getting started).

Bakhaow commented 1 year ago

Having the same issue i came there but i found a way to pass through this error:

Wanting to create a react app with "npx create-react-app ." ?

use instead

cd ../ npm i create-react-app@latest npx create-react-app cd

Hope it can helps

& Also Enjoy Coding

Rishijay commented 1 year ago

Just like any other library upgrade, I upgraded "create-react-app" and it worked in 2 simple steps :-

  1. Global Uninstall Create React App (just to make sure previous version doesn't conflict with latest) :- npm uninstall -g create-react-app

  2. Global Install Create React App (by default it installs latest version) :- npm install -g create-react-app

Now, create react app with npx create-react-app <your-project-name>

Weapon-X6 commented 1 year ago

buggy

I use React here and there, everything I come back is buggy

cabiamdos commented 6 months ago

to fix it go to %appdata%/npm/node_modules if you are on windows, and in the createReactApp.js remove the "process.exit(1)" image image image and the if else statement so that the log part doesn't execute