Skip to content

Prod build is built in layer folder instead of root dir when layer config is loaded via ESM #33733

@dword-design

Description

@dword-design

Environment

  • Operating System: Darwin
  • Node Version: v22.16.0
  • Nuxt Version: 4.2.1
  • CLI Version: 3.30.0
  • Nitro Version: 2.12.9
  • Package Manager: pnpm@10.22.0
  • Builder: -
  • User Config: extends
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://github.com/dword-design/demo-nuxt-layers-wrong-outdir

  1. pnpm install --frozen-lockfile
  2. pnpm build

Describe the bug

Expected: .output is generated in cwd.
Actual: .output is generated in foo subfolder.

This always happens when Jiti imports the layer using ESM instead of transpiling:

  • When the layer config is a .js file and "type": "module" is set in package.json
  • When the layer config is an .mjs file
  • When the layer is in node_modules (which imho is a frequent case, including mine)

It works as expected when nuxt.config.ts is a TypeScript file.

I think the issue is that when importing using ESM, the ESM cache is there and there is probably some place where Nuxt is setting rootDir in an already-imported layer or sth. With transpiling, Jiti will always do a clean import.

Looks like the issue came in with nuxt@3.14.0. There Jiti@2 was introduced that adds native ESM imports. I guess that's where it came in, but I think the root cause is a mutated data issue in Nuxt.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions