From 73b16111e2f5eeb921ef3498c50ce6e942d5baa2 Mon Sep 17 00:00:00 2001 From: Alex Z Date: Fri, 3 Apr 2026 15:52:53 -0700 Subject: [PATCH 1/2] perf(nuxi): use `loadNuxtConfig` instead of `loadNuxt` in preview command `nuxt preview` called `loadNuxt({ ready: true })` just to resolve the output directory. This runs all user module `setup()` functions, which may emit false-positive warnings about env vars that are already baked into the build output (e.g. `@nuxtjs/supabase` warning about missing `SUPABASE_URL`). Replace with `loadNuxtConfig`, which reads `nuxt.config.ts` and resolves `nitro.output.dir` without initializing any modules. Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/nuxi/src/commands/preview.ts | 42 ++++++++++----------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/packages/nuxi/src/commands/preview.ts b/packages/nuxi/src/commands/preview.ts index fadc2793e..6939a2d5b 100644 --- a/packages/nuxi/src/commands/preview.ts +++ b/packages/nuxi/src/commands/preview.ts @@ -37,37 +37,27 @@ const command = defineCommand({ const cwd = resolve(ctx.args.cwd || ctx.args.rootDir) - const { loadNuxt } = await loadKit(cwd) - - const resolvedOutputDir = await new Promise((res) => { - loadNuxt({ + // Resolve the output directory from config without running module setup + // (which may emit warnings about env vars already baked into the build). + const { loadNuxtConfig } = await loadKit(cwd) + const config = await loadNuxtConfig({ + cwd, + dotenv: { cwd, - dotenv: { - cwd, - fileName: ctx.args.dotenv, - }, - envName: ctx.args.envName, // c12 will fall back to NODE_ENV - ready: true, - overrides: { - ...(ctx.args.extends && { extends: ctx.args.extends }), - modules: [ - function (_, nuxt) { - nuxt.hook('nitro:init', (nitro) => { - res(resolve(nuxt.options.srcDir || cwd, nitro.options.output.dir || '.output', 'nitro.json')) - }) - }, - ], - }, - }).then(nuxt => nuxt.close()).catch(() => '') + fileName: ctx.args.dotenv, + }, + envName: ctx.args.envName, + overrides: { + ...(ctx.args.extends && { extends: ctx.args.extends }), + }, }) - const defaultOutput = resolve(cwd, '.output', 'nitro.json') // for backwards compatibility + const outputDir = config.nitro?.output?.dir || '.output' + const nitroJSONPath = resolve(config.srcDir || cwd, outputDir, 'nitro.json') - const nitroJSONPaths = [resolvedOutputDir, defaultOutput].filter(Boolean) - const nitroJSONPath = nitroJSONPaths.find(p => existsSync(p)) - if (!nitroJSONPath) { + if (!existsSync(nitroJSONPath)) { logger.error( - `Cannot find ${colors.cyan('nitro.json')}. Did you run ${colors.cyan('nuxi build')} first? Search path:\n${nitroJSONPaths.join('\n')}`, + `Cannot find ${colors.cyan('nitro.json')}. Did you run ${colors.cyan('nuxi build')} first? Search path:\n${nitroJSONPath}`, ) process.exit(1) } From ab194f71387e34259052c7d24b18b2e7961dece8 Mon Sep 17 00:00:00 2001 From: Alex Z Date: Fri, 3 Apr 2026 16:19:22 -0700 Subject: [PATCH 2/2] fix: use rootDir instead of srcDir for output path resolution Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/nuxi/src/commands/preview.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nuxi/src/commands/preview.ts b/packages/nuxi/src/commands/preview.ts index 6939a2d5b..b3a0bbab6 100644 --- a/packages/nuxi/src/commands/preview.ts +++ b/packages/nuxi/src/commands/preview.ts @@ -52,8 +52,8 @@ const command = defineCommand({ }, }) - const outputDir = config.nitro?.output?.dir || '.output' - const nitroJSONPath = resolve(config.srcDir || cwd, outputDir, 'nitro.json') + const outputDir = config.nitro?.output?.dir ?? '.output' + const nitroJSONPath = resolve(config.rootDir || cwd, outputDir, 'nitro.json') if (!existsSync(nitroJSONPath)) { logger.error(