Node.jsをインストールして意気揚々とcreate-appしたらエラーになった。
% npx create-react-app my-react
You are running `create-react-app` 4.0.3, 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/過去にグローバルインストールしたcreate-react-appが古いため怒られていそうです。
解決策
まずはターミナルで教えてくれた通りにアンインストールを行います。
(yarn は入れてないので割愛しました)
$ npm uninstall -g create-react-app
up to date in 73ms続いてcreate-react-appをローカルインストールします。
$ npm install create-react-app
added 64 packages, and audited 66 packages in 5s
5 packages are looking for funding
run `npm fund` for details
Run `npm audit` for details.改めてプロジェクト作成を実行、、、うまくいきました!
$ npx create-react-app my-app
Creating a new React app
...(中略)...
Success! Created my-react
Inside that directory, you can run several commands:
...(中略)...
Happy hacking!
プロジェクトのルートディレクトリでnpm run startを実行すると、http://localhost:3000/で開発サーバーが起動されたことが確認できました!
$ cd my-app
$ npm run start
Compiled successfully!
You can now view my-app in the browser.
Local: http://localhost:3000
めでたし、めでたし!