Nuxt `multiApp` breaks nuxt/test-utils · Issue #1521 · nuxt/test-utils · GitHub
Skip to content

Nuxt multiApp breaks nuxt/test-utils #1521

Open

Description

@RaphaelDDL

Environment

Nuxt project info (That's stackblitz's terminal info):

Operating system Linux 5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
CPU Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz (4 cores)
Node.js version v20.19.1
nuxt/cli version 3.31.3
Package manager npm@10.8.2
Nuxt version 4.2.2
Nitro version 2.12.9
Builder vite@7.3.0
Config compatibilityDate, devtools, future, modules
Modules @nuxt/test-utils/module@3.21.0

Reproduction

https://stackblitz.com/edit/github-sqshpc8h?file=nuxt.config.ts&view=editor

(using stackblitz's template for github/nuxt/test-utils/tree/main/examples/app-vitest, but I removed all non-necessary tests)

Describe the bug

We are moving a project from Vue to Nuxt and we are using future: { multiApp: true } as part of this project's solution. When moving tests, we noticed they don't work and are throwing errors that other projects weren't. Upon further investigation, we pinpointed to the multiApp flag.

Running tests (npm run test) with future: { multiApp: false } passes tests. When changing to future: { multiApp: true }, we got the following errors:

During vitest running the file:

stderr | test/app.nuxt.spec.ts
[nuxt] error caught during app initialization TypeError: Cannot read properties of undefined (reading 'app')
    at setup (/home/projects/jvmikwmyxv.github/node_modules/nuxt/dist/app/plugins/router.js:48:139)
    at eval (/home/projects/jvmikwmyxv.github/node_modules/nuxt/dist/app/nuxt.js:156:60)
    at fn (/home/projects/jvmikwmyxv.github/node_modules/nuxt/dist/app/nuxt.js:238:44)
    at Object.runWithContext (/home/projects/jvmikwmyxv.github/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:4218:18)
    at callWithNuxt (/home/projects/jvmikwmyxv.github/node_modules/nuxt/dist/app/nuxt.js:244:24)
    at eval (/home/projects/jvmikwmyxv.github/node_modules/nuxt/dist/app/nuxt.js:55:41)
    at EffectScope.run (/home/projects/jvmikwmyxv.github/node_modules/@vue/reactivity/dist/reactivity.cjs.js:85:16)
    at Object.runWithContext (/home/projects/jvmikwmyxv.github/node_modules/nuxt/dist/app/nuxt.js:55:31)
    at applyPlugin (/home/projects/jvmikwmyxv.github/node_modules/nuxt/dist/app/nuxt.js:156:39)
    at executePlugin (/home/projects/jvmikwmyxv.github/node_modules/nuxt/dist/app/nuxt.js:175:23)

which is referencing to NuxtPlugin nuxt:router's setup where useRuntimeConfig is not returning an app in useRuntimeConfig().app.baseURL

Image

and Vitest report after finished running shows the following:

 FAIL   nuxt  test/app.nuxt.spec.ts [ test/app.nuxt.spec.ts ]
TypeError: Cannot read properties of undefined (reading 'afterEach')
 ❯ setupNuxt node_modules/@nuxt/test-utils/dist/runtime/shared/nuxt.mjs:6:14
      4|   const nuxtApp = useNuxtApp();
      5|   await nuxtApp.callHook("page:finish");
      6|   useRouter().afterEach(() => nuxtApp.callHook("page:finish"));
       |              ^
      7| }
      8| 
 ❯ eval node_modules/@nuxt/test-utils/dist/runtime/entry.mjs:4:3

There seems to be some kind of issue in Router when multiApp is preset. We do have appId and app.rootId set in nuxt.config, but this made no change to the tests so I did not include in the stackblitz.

Activity

  1. s00d commented on Sep 21, 2026

    @s00d

    If multiApp is fighting a single implicit Nuxt root, a recipe-based harness can help: each app is an explicit recipe { id, root, … } with its own prepare identity, instead of one global setup assuming one app.

    That is how untestutils models targets (clean break, not API-compatible). We dogfood it on a multi-fixture Nuxt module suite — e.g. 265 e2e ~4 min shared prepare:

    https://github.com/s00d/nuxt-i18n-micro/actions/runs/35586385667/job/106290602444

    https://s00d.github.io/untestutils/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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