Nuxt v4.6.0 nightly: `@nuxt/test-utils/module` causes colocated tests to be registered as app files, causing import-protection errors during dev
Maintainers usually reply within 1 day
A pull request for this has already been merged.
- #1834 by @yamachi4416 — merged
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- nuxtjs, typescript
- Domain
- build-system, testing-qa
Research direction
Start with src/module/mock.ts around lines 44–49 and reproduce the failure using the linked StackBlitz setup with @nuxt/test-utils/module enabled and colocated tests. Trace how the module graph registers tests during nuxt dev, then verify that files such as tests/helpers/nuxt-composable.ts are no longer treated as app files or rejected by import protection.
Written by the indexing model from the issue text.
Description
Environment
Nuxt project info:
| Operating system | Linux 5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36 |
| CPU | Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz (8 cores) |
| Node.js version | v22.22.3 |
| nuxt/cli version | 4.0.0-20261002-114954-4cba365 |
| Package manager | [email protected] |
| Nuxt version | 4.6.0-29844781.aec739e9 |
| Nitro version | 2.13.4 |
| Builder | [email protected] |
| Config | compatibilityDate, devtools, modules |
| Modules | @nuxt/test-utils/[email protected] |
Reproduction
https://stackblitz.com/edit/github-95gnhfsg
--> Only shows the general setup. Starting the dev server in the Stackblitz container causes some error in the Nuxt cli package which I didn't manage to solve.
Describe the bug
Hello,
I am currently trying out the latest Nuxt 4.6.0 nightly and encounter some problems related to my test setup. I use colocated tests in my project (__tests__ folders next to the code they are testing) which work fine with Nuxt 4.5. However in Nuxt 4.6 I get the following error on running nuxt dev:
4:59:44 PM ✖ Error: This module cannot be imported in the Vue part of your app. [importing `@nuxt/test-utils/runtime` from
▎ `tests/helpers/nuxt-composable.ts`]
▎
▎ Code:
▎ > 1 | import { mountSuspended } from '@nuxt/test-utils/runtime';
▎ | ^
▎
▎ generated code:
▎ › 1 │ import { mountSuspended } from "@nuxt/test-utils/runtime";
▎ │ ^
▎ 2 │ import { defineComponent } from "vue";
▎ 3 │ import { registerMountCleanup } from "../utils/mount-cleanup";
▎
▎ at <anonymous> tests/helpers/nuxt-composable.ts (generated 1:31)
This helper is used in some of my test files.
I assume something regarding the import protection or how the module graph is scanned has changed in Nuxt 4.6 which exposes this problem.
The issue itself is probably caused by this section here:
https://github.com/nuxt/test-utils/blob/5498f4b9b401e62871b3a36b72959d8d535d63d2/src/module/mock.ts#L44-L49
Removing '@nuxt/test-utils/module' from the modules in the nuxt config solves the problem.
Additional context
No response
Logs
- Dominant language
- TypeScript
- Stars
- 441
- Forks
- 120
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 34
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nuxt/test-utils
-
pending triage
Difficulty 3/5 1-2 days Newbie friendliness 55/100
nuxt/test-utils#1671 · 4 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
pending triage
Difficulty 4/5 3-5 days Newbie friendliness 52/100
nuxt/test-utils#1607 · 2 comments ·
Maintainers usually reply within 1 day
-
`@vitest-environment-options` is not workingPossibly taken @yamachi4416 claimed this 178 days ago. Openpending triage
Difficulty 3/5 1-2 days Newbie friendliness 45/100
nuxt/test-utils#1541 · 2 reactions ·
Maintainers usually reply within 1 day
-
Nuxt `multiApp` breaks nuxt/test-utilsPossibly taken @nicolaspayot claimed this 878 days ago. Openpending triage
Difficulty 4/5 3-5 days Newbie friendliness 48/100
nuxt/test-utils#1521 · 1 comment · 4 reactions ·
Maintainers usually reply within 1 day
-
pending triage
Difficulty 4/5 3-5 days Newbie friendliness 35/100
nuxt/test-utils#1494 ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
melgarafael/DeskcommCRM#3000 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
callstackincubator/simlock#639 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
aws/agentcore-cli#2606 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 7 days
-
ai-driven-qa bug Cosmetic
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day