Skip to content

Commit

Permalink
fix: Symbol.toStringTag on Module is non-enumerable (#1808)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Aug 6, 2022
1 parent 426503c commit 95c1d34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/vite-node/src/client.ts
Expand Up @@ -182,7 +182,11 @@ export class ViteNodeRunner {
const url = pathToFileURL(fsPath).href
const meta = { url }
const exports: any = Object.create(null)
exports[Symbol.toStringTag] = 'Module'
Object.defineProperty(exports, Symbol.toStringTag, {
value: 'Module',
enumerable: false,
configurable: false,
})

this.moduleCache.set(fsPath, { code: transformed, exports })

Expand Down
5 changes: 5 additions & 0 deletions test/core/test/module.test.ts
Expand Up @@ -3,6 +3,11 @@ import { expect, it } from 'vitest'
// @ts-expect-error
import { a, b } from '../src/module-cjs'
import c, { d } from '../src/module-esm'
import * as timeout from '../src/timeout'

it('doesn\'t when extending module', () => {
expect(() => Object.assign(globalThis, timeout)).not.toThrow()
})

it('should work when using cjs module', () => {
expect(a).toBe(1)
Expand Down

0 comments on commit 95c1d34

Please sign in to comment.