From e1cb917638ee3b2d8bf7f01382c8c12754f16862 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Sat, 6 Aug 2022 13:35:14 +0300 Subject: [PATCH] fix: Symbol.toStringTag on Module is non-enumerable --- packages/vite-node/src/client.ts | 6 +++++- test/core/test/module.test.ts | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/vite-node/src/client.ts b/packages/vite-node/src/client.ts index 2d1bd39951aa..308f3fa4f232 100644 --- a/packages/vite-node/src/client.ts +++ b/packages/vite-node/src/client.ts @@ -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 }) diff --git a/test/core/test/module.test.ts b/test/core/test/module.test.ts index f0b6c9b975c4..e34875140fa6 100644 --- a/test/core/test/module.test.ts +++ b/test/core/test/module.test.ts @@ -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)