File tree 1 file changed +9
-10
lines changed
1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -1141,18 +1141,17 @@ async function loadConfigFromBundledFile(
1141
1141
) : Promise < UserConfigExport > {
1142
1142
// for esm, before we can register loaders without requiring users to run node
1143
1143
// 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.
1145
1145
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 )
1152
1146
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 } ` )
1156
1155
}
1157
1156
}
1158
1157
// for cjs, we can register a custom loader via `_require.extensions`
You can’t perform that action at this time.
2 commit comments
chinbor commentedon Jun 27, 2023
基于本次提交后的内容运行vite项目的测试脚本,报错 "The URL must be of scheme file",用提交前的代码没问题
widnwos11
node: 16.15.1
chinbor commentedon Jun 27, 2023
node版本问题导致 #13631