diff --git a/packages/vite-node/src/client.ts b/packages/vite-node/src/client.ts index cd7101506a5a..14c75c3b67eb 100644 --- a/packages/vite-node/src/client.ts +++ b/packages/vite-node/src/client.ts @@ -509,7 +509,7 @@ function exportAll(exports: any, sourceModule: any) { if (exports === sourceModule) return - if (isPrimitive(sourceModule) || Array.isArray(sourceModule)) + if (isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise) return for (const key in sourceModule) { diff --git a/test/core/test/imports.test.ts b/test/core/test/imports.test.ts index a80504031b95..75fc6ec8e984 100644 --- a/test/core/test/imports.test.ts +++ b/test/core/test/imports.test.ts @@ -3,6 +3,13 @@ import { resolve } from 'pathe' import { describe, expect, test } from 'vitest' import { dynamicRelativeImport } from '../src/relative-import' +// @ts-expect-error module is not typed +import promiseExport from '../src/cjs/promise-export' + +test('promise export works correctly', async () => { + await expect(promiseExport).resolves.toEqual({ value: 42 }) +}) + test('dynamic relative import works', async () => { const stringTimeoutMod = await import('./../src/timeout')