diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index cfff5c7a2c..5c83133aa5 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -132,7 +132,7 @@ export const schemaTemplate: NuxtTemplate = { ...modules.map(([configKey, importName]) => ` [${configKey}]?: typeof ${genDynamicImport(importName, { wrapper: false })}.default extends NuxtModule ? Partial : Record` ), - modules.length > 0 ? ` modules?: (NuxtModule | string | [NuxtModule | string, Record] | ${modules.map(([configKey, importName]) => `[${genString(importName)}, Exclude]`).join(' | ')})[],` : '', + modules.length > 0 ? ` modules?: (undefined | null | false | NuxtModule | string | [NuxtModule | string, Record] | ${modules.map(([configKey, importName]) => `[${genString(importName)}, Exclude]`).join(' | ')})[],` : '', ' }', generateTypes(await resolveSchema(Object.fromEntries(Object.entries(nuxt.options.runtimeConfig).filter(([key]) => key !== 'public'))), { diff --git a/packages/schema/src/config/common.ts b/packages/schema/src/config/common.ts index 7270458e9a..6830036626 100644 --- a/packages/schema/src/config/common.ts +++ b/packages/schema/src/config/common.ts @@ -194,9 +194,11 @@ export default defineUntypedSchema({ * function () {} * ] * ``` - * @type {(typeof import('../src/types/module').NuxtModule | string | [typeof import('../src/types/module').NuxtModule | string, Record])[]} + * @type {(typeof import('../src/types/module').NuxtModule | string | [typeof import('../src/types/module').NuxtModule | string, Record] | undefined | null | false)[]} */ - modules: [], + modules: { + $resolve: val => [].concat(val).filter(Boolean) + }, /** * Customize default directory structure used by Nuxt. diff --git a/test/fixtures/basic/extends/bar/nuxt.config.ts b/test/fixtures/basic/extends/bar/nuxt.config.ts index 268da7f8c1..a3d7147bee 100644 --- a/test/fixtures/basic/extends/bar/nuxt.config.ts +++ b/test/fixtures/basic/extends/bar/nuxt.config.ts @@ -1 +1,3 @@ -export default defineNuxtConfig({}) +export default defineNuxtConfig({ + modules: [undefined] +}) diff --git a/test/fixtures/basic/nuxt.config.ts b/test/fixtures/basic/nuxt.config.ts index bf0341553f..8d0cba4650 100644 --- a/test/fixtures/basic/nuxt.config.ts +++ b/test/fixtures/basic/nuxt.config.ts @@ -135,7 +135,9 @@ export default defineNuxtConfig({ function (_, nuxt) { nuxt.options.optimization.treeShake.composables.server[nuxt.options.rootDir] = ['useClientOnlyComposable', 'setTitleToPink'] nuxt.options.optimization.treeShake.composables.client[nuxt.options.rootDir] = ['useServerOnlyComposable'] - } + }, + // To test falsy module values + undefined ], vite: { logLevel: 'silent'