Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(vite-node): coerce to string in import(dep) (#3430)
Co-authored-by: Vladimir <sleuths.slews0s@icloud.com>
  • Loading branch information
jcbhmr and sheremet-va committed May 25, 2023
1 parent f928e9c commit b72ebdb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vite-node/src/client.ts
Expand Up @@ -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)
}

Expand Down
6 changes: 6 additions & 0 deletions test/core/test/imports.test.ts
Expand Up @@ -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')

Expand Down

0 comments on commit b72ebdb

Please sign in to comment.