Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vite-node): coerce to string in import(dep) #3430

Merged
merged 3 commits into from May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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