Skip to content

Commit ff3ce31

Browse files
authoredJun 9, 2023
fix: unexpected config temporary file (#13269)
1 parent 3a98558 commit ff3ce31

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed
 

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

+9-10
Original file line numberDiff line numberDiff line change
@@ -1141,18 +1141,17 @@ async function loadConfigFromBundledFile(
11411141
): Promise<UserConfigExport> {
11421142
// for esm, before we can register loaders without requiring users to run node
11431143
// with --experimental-loader themselves, we have to do a hack here:
1144-
// write it to disk, load it with native Node ESM, then delete the file.
1144+
// convert to base64, load it with native Node ESM.
11451145
if (isESM) {
1146-
const fileBase = `${fileName}.timestamp-${Date.now()}-${Math.random()
1147-
.toString(16)
1148-
.slice(2)}`
1149-
const fileNameTmp = `${fileBase}.mjs`
1150-
const fileUrl = `${pathToFileURL(fileBase)}.mjs`
1151-
await fsp.writeFile(fileNameTmp, bundledCode)
11521146
try {
1153-
return (await dynamicImport(fileUrl)).default
1154-
} finally {
1155-
fs.unlink(fileNameTmp, () => {}) // Ignore errors
1147+
return (
1148+
await dynamicImport(
1149+
'data:text/javascript;base64,' +
1150+
Buffer.from(bundledCode).toString('base64'),
1151+
)
1152+
).default
1153+
} catch (e) {
1154+
throw new Error(`${e.message} at ${fileName}`)
11561155
}
11571156
}
11581157
// for cjs, we can register a custom loader via `_require.extensions`

2 commit comments

Comments
 (2)

chinbor commented on Jun 27, 2023

@chinbor

基于本次提交后的内容运行vite项目的测试脚本,报错 "The URL must be of scheme file",用提交前的代码没问题
widnwos11
node: 16.15.1

chinbor commented on Jun 27, 2023

@chinbor

基于本次提交后的内容运行vite项目的测试脚本,报错 "The URL must be of scheme file",用提交前的代码没问题 widnwos11 node: 16.15.1

node版本问题导致 #13631

Please sign in to comment.