@@ -16,7 +16,7 @@ import { transformRequest } from '../server/transformRequest'
16
16
// This is a workaround since typescript compiles dynamic imports to `require`.
17
17
// Thankfully, when `typescript@4.5.0` lands it won't and this can be removed!
18
18
// See #5197 for notes
19
- const nativeImport = eval ( 'u => import(u)' ) ;
19
+ const nativeImport = eval ( 'u => import(u)' )
20
20
21
21
interface SSRContext {
22
22
global : NodeJS . Global
@@ -97,11 +97,7 @@ async function instantiateModule(
97
97
98
98
const ssrImport = async ( dep : string ) => {
99
99
if ( dep [ 0 ] !== '.' && dep [ 0 ] !== '/' ) {
100
- return nodeImport (
101
- dep ,
102
- mod . file ,
103
- server . config
104
- )
100
+ return nodeImport ( dep , mod . file , server . config )
105
101
}
106
102
dep = unwrapId ( dep )
107
103
if ( ! isCircular ( dep ) && ! pendingImports . get ( dep ) ?. some ( isCircular ) ) {
@@ -183,32 +179,36 @@ async function instantiateModule(
183
179
async function nodeImport (
184
180
id : string ,
185
181
importer : string | null ,
186
- config : ViteDevServer [ 'config' ] ,
182
+ config : ViteDevServer [ 'config' ]
187
183
) {
188
184
let url : string
189
185
// `resolve` doesn't handle `node:` builtins, so handle them directly
190
186
if ( id . startsWith ( 'node:' ) || isBuiltin ( id ) ) {
191
187
url = id
192
188
} else {
193
- url = pathToFileURL ( resolve ( id , importer , config . root , ! ! config . resolve . preserveSymlinks ) ) . toString ( )
189
+ url = pathToFileURL (
190
+ resolve ( id , importer , config . root , ! ! config . resolve . preserveSymlinks )
191
+ ) . toString ( )
194
192
}
195
- const mod = await nativeImport ( url ) ;
196
- return proxyESM ( id , mod ) ;
193
+ const mod = await nativeImport ( url )
194
+ return proxyESM ( id , mod )
197
195
}
198
196
199
197
// rollup-style default import interop for cjs
200
198
function proxyESM ( id : string , mod : any ) {
201
199
return new Proxy ( mod , {
202
200
get ( mod , prop ) {
203
201
if ( prop in mod ) {
204
- return mod [ prop ] ;
202
+ return mod [ prop ]
205
203
}
206
204
// commonjs interop: module whose exports are not statically analyzable
207
205
if ( isObject ( mod . default ) && prop in mod . default ) {
208
206
return mod . default [ prop ]
209
207
}
210
208
// throw an error like ESM import does
211
- throw new SyntaxError ( `The requested module '${ id } ' does not provide an export named '${ prop . toString ( ) } '` )
209
+ throw new SyntaxError (
210
+ `The requested module '${ id } ' does not provide an export named '${ prop . toString ( ) } '`
211
+ )
212
212
}
213
213
} )
214
214
}
0 commit comments