Environment
Nuxt: 4.4.8
Package manager: npm 10 (not reproducible with pnpm)
Node: 22.22.0
OS: macOS 25
Reproduction
Minimal repro: https://github.com/DenisLug/nuxt-layers-reproduction
cd nuxt-layers-reproduction/main
npm install --ignore-scripts
npm run build
Describe the bug
The build results in the following error:
[nitro] ERROR RollupError: node_modules/nuxt-first-level-layer/node_modules/nuxt-second-level-layer/server/api/inner.ts (4:10):
Expected ';', '}' or <eof> (Note that you need plugins to import files that are not JavaScript)
4: interface Payload { from: 'inner-layer'; ok: true }
^
Additional context
I traced the issue to this regex: https://github.com/nuxt/nuxt/blob/main/packages/nitro-server/src/index.ts#L39
It only surfaces under the following conditions:
- npm - pnpm is unaffected because its virtual store layout matches PNPM_NODE_MODULES_RE, which is already greedy.
- TypeScript files under a layer's server/ directory. These are the files Nitro hands to esbuild, which the buggy exclude pattern then skips.
A possible fix would be to make NODE_MODULES_RE greedy up to the last node_modules/, mirroring the pnpm variant:
const NODE_MODULES_RE = /.*\/node_modules\/(.+)$/
I'm not deep enough in this codebase to be confident that's the right call across all the layer-resolution edge cases, so I'll leave the final decision to a maintainer with broader context.
Logs
Environment
Nuxt: 4.4.8
Package manager: npm 10 (not reproducible with pnpm)
Node: 22.22.0
OS: macOS 25
Reproduction
Minimal repro: https://github.com/DenisLug/nuxt-layers-reproduction
cd nuxt-layers-reproduction/main
npm install --ignore-scripts
npm run build
Describe the bug
The build results in the following error:
Additional context
I traced the issue to this regex: https://github.com/nuxt/nuxt/blob/main/packages/nitro-server/src/index.ts#L39
It only surfaces under the following conditions:
A possible fix would be to make NODE_MODULES_RE greedy up to the last node_modules/, mirroring the pnpm variant:
I'm not deep enough in this codebase to be confident that's the right call across all the layer-resolution edge cases, so I'll leave the final decision to a maintainer with broader context.
Logs