@@ -5,6 +5,7 @@ import type { Nuxt, NuxtTemplate, NuxtTypeTemplate, ResolvedNuxtTemplate, TSRefe
55import { withTrailingSlash } from 'ufo'
66import { defu } from 'defu'
77import type { TSConfig } from 'pkg-types'
8+ import { gte } from 'semver'
89import { readPackageJSON } from 'pkg-types'
910
1011import { tryResolveModule } from './internal/esm'
@@ -122,6 +123,12 @@ export async function _generateTypes (nuxt: Nuxt) {
122123 . map ( m => getDirectory ( m . entryPath ) ) ,
123124 )
124125
126+ const isV4 = nuxt . options . future ?. compatibilityVersion === 4
127+
128+ const hasTypescriptVersionWithModulePreserve = await readPackageJSON ( 'typescript' , { url : nuxt . options . modulesDir } )
129+ . then ( r => r ?. version && gte ( r . version , '5.4.0' ) )
130+ . catch ( ( ) => isV4 )
131+
125132 // https://www.totaltypescript.com/tsconfig-cheat-sheet
126133 const tsConfig : TSConfig = defu ( nuxt . options . typescript ?. tsConfig , {
127134 compilerOptions : {
@@ -136,11 +143,11 @@ export async function _generateTypes (nuxt: Nuxt) {
136143 verbatimModuleSyntax : true ,
137144 /* Strictness */
138145 strict : nuxt . options . typescript ?. strict ?? true ,
139- noUncheckedIndexedAccess : nuxt . options . future ?. compatibilityVersion === 4 ,
146+ noUncheckedIndexedAccess : isV4 ,
140147 forceConsistentCasingInFileNames : true ,
141148 noImplicitOverride : true ,
142149 /* If NOT transpiling with TypeScript: */
143- module : 'preserve' ,
150+ module : hasTypescriptVersionWithModulePreserve ? 'preserve' : 'es2022 ',
144151 noEmit : true ,
145152 /* If your code runs in the DOM: */
146153 lib : [
0 commit comments