From aeef6708bd4d75982413c7781ec885fa2f8e3b3f Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Tue, 25 Jul 2023 15:54:39 +0200 Subject: [PATCH] fix: use file extensions on type imports so they work with `moduleResolution: 'node16'` (#13947) --- packages/vite/scripts/postPatchTypes.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/vite/scripts/postPatchTypes.ts b/packages/vite/scripts/postPatchTypes.ts index 51599384059d67..8d170922fcfa36 100644 --- a/packages/vite/scripts/postPatchTypes.ts +++ b/packages/vite/scripts/postPatchTypes.ts @@ -7,10 +7,12 @@ import { rewriteImports, walkDir } from './util' const dir = dirname(fileURLToPath(import.meta.url)) const nodeDts = resolve(dir, '../dist/node/index.d.ts') -// rewrite `types/*` import to relative import +// rewrite `types/*` import to relative import with file extension rewriteImports(nodeDts, (importPath) => { if (importPath.startsWith('types/')) { - return '../../' + importPath + return ( + '../../' + (importPath.endsWith('.js') ? importPath : importPath + '.js') + ) } })