Skip to content

loadNuxtConfig: klona/full stack overflow on jiti JSON-array default import (self-ref .default) #35985

Description

@s00d

Environment

  • Nuxt / @nuxt/kit 4.5.1 (repro). Kit 4.5.0 often survives because it used klona (lite).
  • Relevant change: loadNuxtConfig does klona(resolved.config) via klona/full (no cycle detection).

Reproduction

// locales.json — a JSON array
// [{ "code": "en" }, { "code": "de" }]

// nuxt.config.ts
import locales from './locales.json'

export default defineNuxtConfig({
  // any module option that holds the array is enough; i18n shown as real-world case
  i18n: { locales },
})

Then nuxt prepareMaximum call stack size exceeded in klona/full.

Control: locales: locales.map((l) => ({ ...l })) → OK.

Minimal jiti check (Nuxt loads config with interopDefault: true):

import { createJiti } from 'jiti'
const jiti = createJiti(import.meta.url, { interopDefault: true })
const mod = jiti('./locales.json')
Array.isArray(mod)       // true
mod.default === mod      // true  ← cycle

Native import … with { type: 'json' } does not add that default.

Describe the bug

  1. jiti + interopDefault attaches default to a JSON array module pointing at itself.
  2. Kit 4.5.1 clones the full resolved config with klona/full, which walks .default forever.
  3. Crash happens in loadNuxtConfig before any module setup, so modules cannot sanitize in time.

Path from a patched depth-limited klona looked like: .i18n.locales.default.default…default.0.

Suggested directions

  • Make config clone cycle-safe (WeakSet / use lite where full isn’t needed), and/or
  • Avoid attaching default onto array exports in the jiti path used for nuxt.config.

Workaround for apps: shallow-clone the array before putting it in config.

Seen with nuxt-i18n-micro i18n.locales from a JSON array import; module-side normalize only helps after a successful load.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions