やまだ

create-react-appで作成したプロジェクトのnpm start時のエラー

投稿日:

更新日:

こんにちは!
認証機能を実装する際にセキュリティを担保できるか不安なのでAuth0のサンプルを試している、やまだです。

以下のようにcreate-react-appでReactアプリのひな形を作成し、実行使用としたところエラーが出たので、そちらの解消方法を記載していきます。

npx create-react-app frontend
cd frontend
npm start

エラーの内容は以下のようになっておりました。

There might be a problem with the project dependency tree. It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"webpack-dev-server": "3.11.0"
Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack-dev-server was detected higher up in the tree:

どうやら「"webpack-dev-server": "3.11.0"」が正しく参照できていないようです。 そこでプロジェクト直下のnode_modulesを確認してみたのですが、間違いなく「"webpack-dev-server": "3.11.0"」はインストールされていました。。

さらにエラー内容を見ていくと、このような記載がありました。

C:\Users\[USER]\node_modules\webpack-dev-server(バージョン:3.10.3)
互換性のないバージョンを手動でインストールすると、デバッグが困難な問題が発生することがわかっています。

なるほど!プロジェクト直下ではなく、グローバルのnode_modulesを参照してしまっていたのですね!!

記載されていた「C:\Users\[USER]\node_modules\」にあるwebpack-dev-serverを削除し、改めて「npm start」を実行すると問題なく起動することができました!(自分の場合は、node_modulesごと削除しました)

以上でエラーは解決するかと思います!ではまた!

参考