From 6a87c65262388a918fa6fcdd55afb2d7352757d4 Mon Sep 17 00:00:00 2001 From: patak Date: Tue, 13 Jun 2023 17:01:08 +0200 Subject: [PATCH] fix: timestamp config dynamicImport (#13502) --- 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 98b79a98e47008..0823fa51e7d6f2 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -1144,10 +1144,16 @@ async function loadConfigFromBundledFile( // convert to base64, load it with native Node ESM. if (isESM) { try { + // Postfix the bundled code with a timestamp to avoid Node's ESM loader cache + const configTimestamp = `${fileName}.timestamp:${Date.now()}-${Math.random() + .toString(16) + .slice(2)}` return ( await dynamicImport( 'data:text/javascript;base64,' + - Buffer.from(bundledCode).toString('base64'), + Buffer.from(`${bundledCode}\n//${configTimestamp}`).toString( + 'base64', + ), ) ).default } catch (e) {