From b383e8bef4f1b345f7abb30642730b8193b4f102 Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Tue, 29 Oct 2024 01:41:03 +0900 Subject: [PATCH] fix(config): remove error if require resolve to esm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolve #1666 https://github.com/vitejs/vite/commit/f886f75396cdb5a43ec5377bbbaaffc0e8ae03e9 の反映です。 --- guide/troubleshooting.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/guide/troubleshooting.md b/guide/troubleshooting.md index 6bab5b2d..e2d7674e 100644 --- a/guide/troubleshooting.md +++ b/guide/troubleshooting.md @@ -54,11 +54,12 @@ ESM のみのパッケージを `require` でインポートすると、以下 > Failed to resolve "foo". This package is ESM only but it was tried to load by `require`. -> "foo" resolved to an ESM file. ESM file cannot be loaded by `require`. +> Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/dependency.js from /path/to/vite.config.js not supported. +> Instead change the require of index.js in /path/to/vite.config.js to a dynamic import() which is available in all CommonJS modules. -ESM ファイルは [`require`]() で読み込むことができません。 +Node.js 22 以前では、ESM ファイルはデフォルトでは [`require`]() で読み込むことができません。 -以下のいずれかの方法で、設定を ESM に変換することをお勧めします: +ESM ファイルは [`--experimental-require-module`](https://nodejs.org/docs/latest-v22.x/api/modules.html#loading-ecmascript-modules-using-require) の利用や、Node.js 23 以降、その他のランタイムでは動作する可能性がありますが、まだ以下のいずれかの方法で、設定を ESM に変換することをお勧めします: - 一番近い `package.json` に `"type": "module"` を追加する - `vite.config.js` / `vite.config.ts` を `vite.config.mjs` / `vite.config.mts` にファイル名を変更する