Skip to content

Commit

Permalink
fix: unexpected config temporary file (#13269)
Browse files Browse the repository at this point in the history
  • Loading branch information
s10y10 authored Jun 9, 2023
1 parent 3a98558 commit ff3ce31
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1141,18 +1141,17 @@ async function loadConfigFromBundledFile(
): Promise<UserConfigExport> {
// for esm, before we can register loaders without requiring users to run node
// 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.
// convert to base64, load it with native Node ESM.
if (isESM) {
const fileBase = `${fileName}.timestamp-${Date.now()}-${Math.random()
.toString(16)
.slice(2)}`
const fileNameTmp = `${fileBase}.mjs`
const fileUrl = `${pathToFileURL(fileBase)}.mjs`
await fsp.writeFile(fileNameTmp, bundledCode)
try {
return (await dynamicImport(fileUrl)).default
} finally {
fs.unlink(fileNameTmp, () => {}) // Ignore errors
return (
await dynamicImport(
'data:text/javascript;base64,' +
Buffer.from(bundledCode).toString('base64'),
)
).default
} catch (e) {
throw new Error(`${e.message} at ${fileName}`)
}
}
// for cjs, we can register a custom loader via `_require.extensions`
Expand Down

2 comments on commit ff3ce31

@chinbor
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@chinbor
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

node版本问题导致 #13631

Please sign in to comment.