#36406·nuxt

`nuxt build` rewrites `.nuxt/tsconfig*.json` with paths computed for the build cache directory

Author: denismrteCreated Sep 24, 2026Updated Sep 24, 2026
Labels5.xpossible regression

Environment

Operating system macOS 27.0.0, arm64
Node.js v24.19.0
Package manager pnpm 11.22.0
Nuxt [email protected] (current main) and 5.0.0-29835210.f258408a
Nitro 3.0.260903-beta
Builder vite 8.3.0
TypeScript 7.0.2

Reproduction

Self-contained — five small files and a script, no repository needed.

package.json

json
{
  "private": true,
  "type": "module",
  "dependencies": {
    "nuxt": "npm:[email protected]",
    "vue": "3.5.43",
    "vue-router": "5.3.1"
  },
  "devDependencies": {
    "typescript": "7.0.2"
  }
}

nuxt.config.ts

typescript
export default defineNuxtConfig({
  devtools: { enabled: false },
  telemetry: false,
})

nuxt.schema.ts

typescript
export default {}

app/app.vue

xml
<template>
  <p>hello</p>
</template>

app/utils/counter.ts

typescript
import { useState } from '#imports'

export const useCounter = () => useState('counter', () => 0)

repro.sh

bash
#!/bin/sh
# nuxt prepare, then nuxt build, then remove the build cache; after each step, report whether the
# generated tsconfigs changed, whether the node project still lists nuxt.schema.ts, and the number
# of type errors in the app project.
rm -rf .nuxt .output node_modules/.cache snap
report() {
  mkdir -p "snap/$1" && cp .nuxt/tsconfig*.json "snap/$1/"
  schema=$(npx tsc -p .nuxt/tsconfig.node.json --listFilesOnly | grep -c 'nuxt.schema.ts$')
  errors=$(npx tsc -p .nuxt/tsconfig.app.json --noEmit | grep -c 'error TS')
  echo "$1: nuxt.schema.ts in the node project: $schema, type errors in the app project: $errors"
}
npx nuxt prepare > /dev/null 2>&1 && report after-prepare
npx nuxt build > /dev/null 2>&1 && report after-build
rm -rf node_modules/.cache && report after-cache-removal
diff -r snap/after-prepare snap/after-build | grep '^[<>]'
bash
pnpm install && ./repro.sh

Describe the bug

nuxt build (which builds into node_modules/.cache/nuxt/.nuxt when .nuxt exists) rewrites all five .nuxt/tsconfig{,.app,.server,.shared,.node}.json that nuxt prepare generated, with paths computed for the build cache directory while the files are written into .nuxt/:

after-prepare: nuxt.schema.ts in the node project: 1, type errors in the app project: 0
after-build: nuxt.schema.ts in the node project: 0, type errors in the app project: 0
after-cache-removal: nuxt.schema.ts in the node project: 0, type errors in the app project: 1
  • compilerOptions.paths for #build, #build/*, #imports, #components and #app-manifest change from ./imports, ., … to ../node_modules/.cache/nuxt/.nuxt/imports, ../node_modules/.cache/nuxt/.nuxt, …, so the project's types now come from the last production build. Once that cache is gone, #imports no longer resolves: app/utils/counter.ts(1,26): error TS2307: Cannot find module '#imports' or its corresponding type declarations. — while .nuxt/imports.d.ts is still there.
  • tsconfig.node.json's include changes from ../nuxt.schema.* and ../layers/*/nuxt.schema.* to ../../../../nuxt.schema.* and ../../../../layers/*/nuxt.schema.*: relative to the cache directory, but written into .nuxt/, where they point three levels above the project root. The project's own nuxt.schema.ts drops out of the node project.

The next nuxt prepare writes the .nuxt/-relative paths back. Measured twice on each version:

version nuxt build after nuxt prepare build's tsconfigs written to
5.0.0-29836693.3006e5ac (main), 5.0.0-29835210.f258408a rewrites all five .nuxt/
5.0.0-29794567.4ffbc756 (#34646) rewrites all five .nuxt/
5.0.0-29793004.2f401585 (its parent) leaves all five byte-identical node_modules/.cache/nuxt/.nuxt/
5.0.0-29787188.1d507ee7 leaves all five byte-identical node_modules/.cache/nuxt/.nuxt/

On 2f401585 the same repro.sh reports 1, 0 after each of the three steps.

It starts at #34646 (4ffbc756, "ensure tsconfigs exist before build"). That change adds typesDir — the directory the project's tsconfig.json references — and writes the generated tsconfigs there even when the build uses another buildDir; most of the relative paths inside them moved from buildDir to typesDir in the same change. Two inputs still resolve against buildDir:

  • packages/nuxt/src/core/schema.ts (lines 61–62 on main) pushes relative(nuxt.options.buildDir, join(nuxt.options.rootDir, 'nuxt.schema.*')) and the layers/* counterpart into the node project's include.
  • the paths entries come from nuxt.options.alias, where #build and the aliases under it point into the build's buildDir; _generateTypes resolves each alias and writes it relative to typesDir.

Additional context

Found by comparing .nuxt/tsconfig*.json before and after nuxt build while moving an app to a newer nightly.