0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[エラー解決] ReactのWebアプリケーションで白紙ページが表示されたまま

Last updated at Posted at 2025-02-01

概要

ほぼタイトルのままですが、
Reactでとあるアプリケーションを開発していたのですが、何らかのタイミングで白紙ページのまま各画面が白紙ページのままとなってしまいました
そのエラーを解決した際の記録を残しておきます

環境

  • React 18.3.1
  • TypeScript 5.6.2
  • vite 6.0.5

現象

開発時のコードで、npm run dev でWebアプリケーションを起動
ブラウザでページを表示しようとしても、白紙ページのまま

ブラウザのコンソールにはエラー原因と思われるものは表示されていませんでした

原因

main.tsxの読込コードを誤って削除してしまっていた
main.tsxが読み込まれなければ、当然、root にレンダリングされる事が無いから白紙ページのままでした。
Appのコードがそもそも読み込まれていなければ、エラーそのものも出力されることも無いと言うオチでした。

修正前

index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Media Control</title>
  </head>
  <body>
    <div id="root"></div>
  </body>
</html>

修正後

index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Media Control</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script> <!-- ←ここを間違えて削除してしまっていた -->
  </body>
</html>

まとめ

  • 小まめにGitコミットを残して、動く状態を残しておけば良かったと思いました
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?