From a20267bb93118468a2e20f0f77b77ed7bfa94165 Mon Sep 17 00:00:00 2001 From: Kazushi Konosu Date: Fri, 29 Nov 2024 16:49:04 +0900 Subject: [PATCH] fix: don't store temporary vite config file in `node_modules` if deno (#18823) --- packages/vite/src/node/config.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 6c65a2aaaa9012..47b495e1b994d7 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -1858,7 +1858,13 @@ async function loadConfigFromBundledFile( // with --experimental-loader themselves, we have to do a hack here: // write it to disk, load it with native Node ESM, then delete the file. if (isESM) { - const nodeModulesDir = findNearestNodeModules(path.dirname(fileName)) + // Storing the bundled file in node_modules/ is avoided for Deno + // because Deno only supports Node.js style modules under node_modules/ + // and configs with `npm:` import statements will fail when executed. + const nodeModulesDir = + typeof process.versions.deno === 'string' + ? undefined + : findNearestNodeModules(path.dirname(fileName)) if (nodeModulesDir) { await fsp.mkdir(path.resolve(nodeModulesDir, '.vite-temp/'), { recursive: true,