diff --git a/packages/vite-node/src/client.ts b/packages/vite-node/src/client.ts index 6445078eb36e..899bca236b59 100644 --- a/packages/vite-node/src/client.ts +++ b/packages/vite-node/src/client.ts @@ -267,7 +267,7 @@ export class ViteNodeRunner { const mod = this.moduleCache.getByModuleId(moduleId) const request = async (dep: string) => { - const [id, depFsPath] = await this.resolveUrl(dep, fsPath) + const [id, depFsPath] = await this.resolveUrl(`${dep}`, fsPath) return this.dependencyRequest(id, depFsPath, callstack) } diff --git a/test/core/test/imports.test.ts b/test/core/test/imports.test.ts index 83af8458beac..646bd9ec3945 100644 --- a/test/core/test/imports.test.ts +++ b/test/core/test/imports.test.ts @@ -52,6 +52,12 @@ test('data with dynamic import works', async () => { expect(hi).toBe('hi') }) +test('dynamic import coerces to string', async () => { + const dataUri = 'data:text/javascript;charset=utf-8,export default "hi"' + const { default: hi } = await import({ toString: () => dataUri } as string) + expect(hi).toBe('hi') +}) + test('dynamic import has Module symbol', async () => { const stringTimeoutMod = await import('./../src/timeout')