Skip to content

Commit

Permalink
fix: add Module symbol to export object (#951)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalvenschraut committed Mar 16, 2022
1 parent aba4ea8 commit 1c6ffca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/vite-node/src/client.ts
Expand Up @@ -83,7 +83,8 @@ export class ViteNodeRunner {

// disambiguate the `<UNIT>:/` on windows: see nodejs/node#31710
const url = pathToFileURL(fsPath).href
const exports: any = {}
const exports: any = Object.create(null)
exports[Symbol.toStringTag] = 'Module'

this.setCache(id, { code: transformed, exports })

Expand Down
13 changes: 13 additions & 0 deletions test/core/test/imports.test.ts
Expand Up @@ -32,3 +32,16 @@ test('data with dynamic import works', async() => {
const { default: hi } = await import(dataUri)
expect(hi).toBe('hi')
})

test('dynamic import has Module symbol', async() => {
const stringTimeoutMod = await import('./../src/timeout')

// @ts-expect-error The symbol won't exist on the import type
expect(stringTimeoutMod[Symbol.toStringTag]).toBe('Module')
})

test('dynamic import has null prototype', async() => {
const stringTimeoutMod = await import('./../src/timeout')

expect(Object.getPrototypeOf(stringTimeoutMod)).toBe(null)
})

0 comments on commit 1c6ffca

Please sign in to comment.