0
0

More than 1 year has passed since last update.

Reactでyarn startができなくなってしまった

Last updated at Posted at 2022-11-15

何の前触れもなく突然yarn startができなくなってしまった

エラーは下記の通り

yarn run v1.22.17
$ react-scripts start
Could not find a required file.
  Name: index.js
  Searched in: /Users/name/folder/React/react-app/src  // ←←名前載ってしまうので一部書き換えてます
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

もちろんbuildしても Could not find a required file. と言われる

エントリーポイントであるindex.jsが見つからない?と言われているっぽい・・・(でもパスは書き換えてないし・・・バージョンかな??)
依存関係を解決しようとバージョンが変えられたのかと思い、package.jsonに書かれているバージョンが過去のものと相違しているかをチェックしたが何も変わっていなかった。

エラー文のSearched in:を見てパスは合っているかを確認してみる

エントリーポイントが記載されている/node_modules/react-scripts/config/paths.jsを確認してみると
appIndexJs: resolveModule(resolveApp, 'src/index'),という記載になっていたが
まさかのsrc配下にindex.jsはなかった。
スクリーンショット 2022-11-15 10.50.30.png

src/js/index.jsにあったのだ。(だが移動させた後もしばらくビルドもスタートもできていたんだが・・・)

パスを書き換えてみる

/node_modules/react-scripts/config/paths.js
appIndexJs:に記載されているパスをsrc/js/index.jsに変更してスタートしてみると・・・

できました!!(警告返されてますがローカルは無事起動できてました笑)

スクリーンショット 2022-11-15 10.31.46.png

このようなエラーが返ってきたらパスとバージョンを疑ってみることをまず先決しようかとおもいます。
細やかなご指摘部分でも、あったらぜひご教授ください!m(_ _)m

0
0
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
0
0