29
12

More than 1 year has passed since last update.

npx create-react-app 出来ない時

Posted at

エラーが出た

いつものように、React アプリを npx で立ち上げようとしたら、エラーが出た。

$ npx create-react-app my-app
Need to install the following packages:
  create-react-app
Ok to proceed? (y) y

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 uninstall -g create-react-app

up to date, audited 1 package in 237ms

found 0 vulnerabilities

ダメ。

$ yarn global remove create-react-app
[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.

ダメ。

global にいないんじゃ仕方ないね。

つーか、いまインストールしたのが古いとは?!

最初に聞かれたじゃないですか。

Need to install the following packages:
  create-react-app

React 公式にも、

When you run npx create-react-app my-app it automatically installs the latest version of Create React App. - via. Updating to New Releases

と、最新バージョンがインストールされるって書いてある。エラーメッセージおかしくない?

キャッシュをクリアする

$ npx clear-npx-cache

うまく行った。人に聞けない時期に、謎エラーは起こりますよね。

まとめ

We no longer support global installation of Create React App.

と言っているように、global インストールはサポートしなくなったので、global にインストールされている場合は、

  • npm uninstall -g create-react-app
  • yarn global remove create-react-app

等を試みて削除。$ which create-react-app で見つかる場合は、それも内容確認して削除。
その上で、キャッシュが悪さしているようなので、

$ npx clear-npx-cache

これで改めて、npx create-react-app my-app すると、うまく行く。yarn create react-app my-appだと、出ないのかな。

ついでに、node, npm, yarn とかのバージョンは(慎重に上げて)新年を迎えましょう。

では、良いお年を。

29
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29
12