From b72ebdb9132a95bc501d31d9afd08010a7089e70 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Thu, 25 May 2023 04:27:29 -0500 Subject: [PATCH] fix(vite-node): coerce to string in import(dep) (#3430) Co-authored-by: Vladimir --- packages/vite-node/src/client.ts | 2 +- test/core/test/imports.test.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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')