English

​​React​TypeScript,Vite,トラブルシュート

Thumbnail of post image 181

「もっと見る」で一覧を継ぎ足したときなどに出る「Encountered two children with the same key」は、key に同じ値が2つあるという知らせです。消したはずの行が画面に残ることを確かめ、3つの原因ご ...

​​React​TypeScript,Vite,トラブルシュート

Thumbnail of post image 001

プロフィール編集でAPIから読み込んだ値を、そのまま入力欄のvalueに渡すと、ページを開いただけで「changing an uncontrolled input to be controlled」が出ます。最初のvalueがunde ...

​​React​TypeScript,Vite,トラブルシュート

Thumbnail of post image 119

会員登録やプロフィール編集のフォームで、入力欄の state を null で始めると出る React の警告の直し方です。null のままだと「消す」ボタンでも文字が消えませんでした。初期値を空文字にするか、?? ” で ...

​​React​TypeScript,Vite,トラブルシュート

Thumbnail of post image 196

React で2つの要素を並べて return すると、Vite で「Adjacent JSX elements must be wrapped in an enclosing tag.」と出ます。… で囲むと消えることを ...

​​React​HTML,TypeScript,Vite

Thumbnail of post image 096

表で1件ごとに2行を出すときや、dl の dt と dd を組で並べるときは、React の Fragment に key を付けて map で返します。div で囲んだときのエラーや、index を key にして並べ替えると入力し ...

​​npm​Node.js,nvm,Vite,トラブルシュート

Thumbnail of post image 053

npm install の「npm warn EBADENGINE Unsupported engine」は、パッケージが求める Node.js と今の Node.js が合わないときの警告です。Vite 7 を Node.js 20 ...

​​React​TypeScript,Vite,トラブルシュート

Thumbnail of post image 093

自作コンポーネントで受け取った props を {…props} で div や li にそのまま渡すと、React does not recognize the `isActive` prop on a DOM elem ...

​​React​CommonJS,TypeScript,Vite,トラブルシュート

Thumbnail of post image 154

npm パッケージのコンポーネントを import したら画面が真っ白になり、コンソールに Element type is invalid と出るのは、default と名前付きの import を取り違えたときです。全文と直し方を確 ...

​​React​TypeScript,Vite,トラブルシュート

Thumbnail of post image 187

HTML をコピーして JSX に class や for と書くと、コンソールに Invalid DOM property `class`. Did you mean `className`? と出ます。className や ht ...

​​React​Playwright,TypeScript,Vite,テスト

Thumbnail of post image 075

バックエンドを動かさずに、React の画面のエラー表示や読み込み中の表示をテストしたいときは、Playwright の page.route で API をモックできます。500 エラー、通信の失敗、応答が届くまでの表示、POST ...

​​JavaScript​ES Modules,Vite,トラブルシュート

Thumbnail of post image 104

Vite の開発サーバーで開いた画面に何も出ず、コンソールに「does not provide an export named」と出るのは、import した名前が相手のファイルで export されていないときです。エラーを起こし、 ...

​​Node.js​Linux,Vite,トラブルシュート

Thumbnail of post image 030

Linux で Vite の開発サーバーを動かし、保存しても画面が更新されない(ホットリロードが効かない)とき、起動時に出ている「ENOSPC: System limit for number of file watchers rea ...

​​React​TypeScript,Vite,トラブルシュート

Thumbnail of post image 015

コンポーネントを でなく {Greeting} と書いたり、関数を () なしで書いたりすると、そこだけ何も表示されず、コンソールに Functions are not valid as a React child と出ます。タグで書 ...

​​React​Playwright,TypeScript,Vite,テスト

Thumbnail of post image 176

CSSの修正やライブラリの更新で React の画面が崩れていないかを、Playwright の toHaveScreenshot() でスクリーンショットを比べて確かめる、ビジュアルリグレッションテストの書き方です。時刻を隠す ma ...

​​React​SVG,SVGR,TypeScript,Vite,vite-plugin-svgr

Thumbnail of post image 190

Vite で SVG を import すると URL の文字列になります。vite-plugin-svgr を入れて ?react を付けると React コンポーネントになり、アイコンの色を文字色に合わせたり、大きさを props ...

​​React​React Router,TypeScript,Vite,Vitest,トラブルシュート

Thumbnail of post image 019

React Router の useNavigate で、ボタンからページを移動させようとしたときに出る「useNavigate() may be used only in the context of a component.」の原 ...

​​TypeScript​CSS Modules,Vite,トラブルシュート

Thumbnail of post image 045

React や Vite で CSS Modules を使うと、tsc で TS2307: Cannot find module ‘./styles.module.css’ が出ることがあります。宣言ファイルや ...

​​JavaScript​Chromium,Vite,トラブルシュート

Thumbnail of post image 043

fetch で API を呼んで res.json() を実行したときの「Unexpected token ‘<', "<!DOCTYPE "… is not vali ...

​​Lighthouse​Chart.js,JavaScript,TypeScript,Vite

Thumbnail of post image 060

Lighthouse の「使用していない JavaScript の削減」は、ボタンで使うライブラリを import() で後から読み込むと消えます。検証では最初に読む JavaScript が約 71KiB から約 1.6KiB にな ...

​​Playwright​E2Eテスト,TypeScript,Vite

Thumbnail of post image 125

Playwright の webServer に開発サーバーの起動コマンドと URL を書くと、E2E テストの前にサーバーを起動し、終わったら止めてくれます。Vite で試し、起動待ちの間隔、404 が返ると待ちが終わらない例、止め ...

​​React​oxlint,TypeScript,Vite,トラブルシュート

Thumbnail of post image 040

一覧の props をオブジェクトにまとめて {…props} で渡すと、「A props object containing a “key” prop is being spread into J ...

​​React​TypeScript,Vite,トラブルシュート

Thumbnail of post image 070

API から取ってくる一覧を map で表示すると、画面が真っ白になり Cannot read properties of undefined (reading ‘map’) と出ます。届く前の配列が unde ...

​​Node.js​Linux,Vite,トラブルシュート

Thumbnail of post image 039

開発サーバーを起動したときの「EADDRINUSE: address already in use」は、ポートが使用中のときに出ます。ss や lsof で使っているプログラムを見つけて止めるか、別のポートで起動すると消えます。Vit ...

​​React​TypeScript,useEffect,useState,Vite,トラブルシュート

Thumbnail of post image 165

子コンポーネントから親の state を変えると出る「Cannot update a component」の警告は、子のレンダー中に親の set 関数を呼んでいるのが原因です。親で計算するか、onClick に関数を渡す形に直すと消え ...