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
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.
Environment
Nuxt project info (That's stackblitz's terminal info):
Linux 5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz (4 cores)v20.19.13.31.3npm@10.8.24.2.22.12.9vite@7.3.0compatibilityDate,devtools,future,modules@nuxt/test-utils/module@3.21.0Reproduction
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) withfuture: { multiApp: false }passes tests. When changing tofuture: { multiApp: true }, we got the following errors:During vitest running the file:
which is referencing to NuxtPlugin
nuxt:router's setup whereuseRuntimeConfigis not returning an app inuseRuntimeConfig().app.baseURLand Vitest report after finished running shows the following:
There seems to be some kind of issue in Router when multiApp is preset. We do have
appIdandapp.rootIdset innuxt.config, but this made no change to the tests so I did not include in the stackblitz.