Skip to content

Commit b0bfa01

Browse files
authoredJul 6, 2023
fix: revert import config module as data (#13731)
1 parent 3f4e36e commit b0bfa01

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed
 

‎packages/vite/src/node/config.ts

+10-15
Original file line numberDiff line numberDiff line change
@@ -1150,23 +1150,18 @@ async function loadConfigFromBundledFile(
11501150
): Promise<UserConfigExport> {
11511151
// for esm, before we can register loaders without requiring users to run node
11521152
// with --experimental-loader themselves, we have to do a hack here:
1153-
// convert to base64, load it with native Node ESM.
1153+
// write it to disk, load it with native Node ESM, then delete the file.
11541154
if (isESM) {
1155+
const fileBase = `${fileName}.timestamp-${Date.now()}-${Math.random()
1156+
.toString(16)
1157+
.slice(2)}`
1158+
const fileNameTmp = `${fileBase}.mjs`
1159+
const fileUrl = `${pathToFileURL(fileBase)}.mjs`
1160+
await fsp.writeFile(fileNameTmp, bundledCode)
11551161
try {
1156-
// Postfix the bundled code with a timestamp to avoid Node's ESM loader cache
1157-
const configTimestamp = `${fileName}.timestamp:${Date.now()}-${Math.random()
1158-
.toString(16)
1159-
.slice(2)}`
1160-
return (
1161-
await dynamicImport(
1162-
'data:text/javascript;base64,' +
1163-
Buffer.from(`${bundledCode}\n//${configTimestamp}`).toString(
1164-
'base64',
1165-
),
1166-
)
1167-
).default
1168-
} catch (e) {
1169-
throw new Error(`${e.message} at ${fileName}`)
1162+
return (await dynamicImport(fileUrl)).default
1163+
} finally {
1164+
fs.unlink(fileNameTmp, () => {}) // Ignore errors
11701165
}
11711166
}
11721167
// for cjs, we can register a custom loader via `_require.extensions`

0 commit comments

Comments
 (0)
Please sign in to comment.