Skip to content

Commit b72ebdb

Browse files
jcbhmrsheremet-va
andauthoredMay 25, 2023
fix(vite-node): coerce to string in import(dep) (#3430)
Co-authored-by: Vladimir <sleuths.slews0s@icloud.com>
1 parent f928e9c commit b72ebdb

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
 

‎packages/vite-node/src/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export class ViteNodeRunner {
267267
const mod = this.moduleCache.getByModuleId(moduleId)
268268

269269
const request = async (dep: string) => {
270-
const [id, depFsPath] = await this.resolveUrl(dep, fsPath)
270+
const [id, depFsPath] = await this.resolveUrl(`${dep}`, fsPath)
271271
return this.dependencyRequest(id, depFsPath, callstack)
272272
}
273273

‎test/core/test/imports.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ test('data with dynamic import works', async () => {
5252
expect(hi).toBe('hi')
5353
})
5454

55+
test('dynamic import coerces to string', async () => {
56+
const dataUri = 'data:text/javascript;charset=utf-8,export default "hi"'
57+
const { default: hi } = await import({ toString: () => dataUri } as string)
58+
expect(hi).toBe('hi')
59+
})
60+
5561
test('dynamic import has Module symbol', async () => {
5662
const stringTimeoutMod = await import('./../src/timeout')
5763

0 commit comments

Comments
 (0)