create-react-app: "npx create-react-app my-app" stopped working in 4.0.3

Describe the bug

/tmp
▶ npx create-react-app my-app

You are running `create-react-app` 4.0.1, which is behind the latest release (4.0.3).

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 ERR! code 1
npm ERR! path /private/tmp
npm ERR! command failed
npm ERR! command sh -c create-react-app my-app

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/peterbe/.npm/_logs/2021-02-23T16_06_05_071Z-debug.log

/tmp
▶ npx --version
7.5.6

If create-react-app is not meant to work with npx, then https://create-react-app.dev/docs/getting-started/ is wrong.

Did you try recovering your dependencies?

not applicable

Which terms did you search for in User Guide?

  • npx
  • getting started

Environment

OSX Big Sur npm 7.5.6 node v15.2.1

Steps to reproduce

cd /tmp/
npx create-react-app my-app

Expected behavior

That it should create a directory called my-app.

Actual behavior

See error above.

Reproducible demo

Not applicable.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 13
  • Comments: 40 (2 by maintainers)

Most upvoted comments

I just encountered this problem as well.

As a possible workaround, this worked for me:

npx create-react-app@latest my-app

This same kind of issue has been reported several times now:

  • #10518 “start fails right after create-react-app”
  • #10495 “Not working after update”
  • #10132 “npx create-react-app is not working”
  • #10127 “Issues with running npx create-react-app on node 15.2.1”
  • #10133 “npx create-react-app my-app is isn’t installing the packages and i try uninstalling npm using -g but still”
  • #9910 “error running npx create-react-app@next”

These were all ultimately resolved with either:

npx create-react-app@latest my-app

Or, in one case (https://github.com/facebook/create-react-app/issues/10495#issuecomment-772893155), the exact opposite of what the error message tells you to do:

npm install -g create-react-app

npx create-react-app my-app

I suspect this is because the warning against “global” installs is really just checking for “is the version being run the latest version” which would be OK immediately after installing it globally, but then wouldn’t be OK two weeks & two new versions later.

There are also a lot of solutions that suggest completely uninstalling and reinstalling node & npm, which I think is mostly a really dramatic way to ensure you have cleared npm’s (and presumably npx’s) cache of installed packages.

I think there are two scenarios that can happen, and I think the error message is shown for both but the contents of the error message only apply to one of the scenarios.

  • The version of create-react-app run being out-of-date because it was installed globally
    • ✅ show error message, instructions to uninstall globally apply
    • ▶ Resolved with instructions in error message
  • The version of create-react-app run being out-of-date because it was cached by npx or npm init somewhere
    • ❌ shows same error message, instructions don’t help at all, lots of stuck people with issues
    • ▶ Resolved by npx create-react-app@latest my-app

I also don’t think it helps that the error message is so definitive about the global install being the only reason you’re seeing the error (it’s not checking for a global install after all, only checking if there’s a newer version)

I just encountered this problem as well.

As a possible workaround, this worked for me:

npx create-react-app@latest my-app

Thanks! This worked for me.

Latest version of npm fixed it for me.

npm install -g npm@latest

then: npx create-react-app myapp

<strike> asks: `Need to install the following packages: create-react-app Ok to proceed? (y)` </strike>

Running from terminal in VS code did not ask this, and seems to worked as usual.

This still buggy at create-react-app@4.0.3 by npx@7.18.1 which seems to come with node@16.4.1

Get around is to install create-react-app in separate project that can later be deleted.

In you parent directory:

mkdir cra
cd cra
yarn init --yes
yarn add create-react-app
cd ..
./cra/node_modules/.bin/create-react-app <my-app-name>
rm -r cra
cd <my-app-name>
yarn start

just update npx to latest version => npm update npx

I did some digging, and this may be an npm bug, as we did research this at the time and as I understood, both npx and yarn create use the latest version - using the cached version only if that is the latest version.

It looks like this is fixed in the latest releases of npm. If you can try that, and report back, that would be greatly appreciated!

This was the trail I took:

npx clear-npx-cache fixed the issue for me: I no longer have to specify @latest to get the command to work. Should work as long as your npm version is >= 7.5.2, I believe.

I just encountered this problem as well.

As a possible workaround, this worked for me:

npx create-react-app@latest my-app

Thanks! It worked.

Hi,

I have tried all of the solutions but this worked for me - leaving the npm/npx and only using create-react-app my-app cmd ignores the error You are running 'create-react-app' 4.0.2, which is behind the latest release (4.0.3). and builds the project file.

Hope this would be helpful!