高木のブログ

npx で実行するコマンドが古かった時は、キャッシュをクリアしてあげると良い

· 130 words · 1 minutes to read
Tags: npx Node.js

問題 🔗

Create React App で React アプリを作ろうとしたらエラーが出た

$ 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/

npx で実行しているのに古いバージョンと出ている謎現象

解決方法 🔗

npx のキャッシュをクリアする

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

...省略...

Happy hacking!

無事プロジェクトが作れた

$ npx create-react-app --version
5.0.0

バージョンも確認すると、v5.0.0 になっている

補足 🔗

バグ? 🔗

キャッシュがクリアされないのは、npxのバグらしい

https://www.npmjs.com/package/clear-npx-cache

レアケース? 🔗

「clear-npx-cache」でググると、Create React App の事ばかりがヒットするから、もしかするとレアケースなのかもしれない

参考 🔗

React: Create React Appでプロジェクトがつくれない - Qiita

Categories


Tags