-
Notifications
You must be signed in to change notification settings - Fork 101
Description
Environment
- Operating System: Linux
- Node Version: v20.19.1
- Nuxt Version: 4.1.1
- CLI Version: 3.28.0
- Nitro Version: 2.12.5
- Package Manager: pnpm@8.15.6
- Builder: -
- User Config: compatibilityDate, devtools, modules, typescript
- Runtime Modules: @nuxt/test-utils/module@3.19.2
- Build Modules: -
Reproduction
https://stackblitz.com/edit/nuxt-starter-yt6qbe2t
Describe the bug
In the setup instructions from https://nuxt.com/docs/4.x/getting-started/testing#setup, tsconfig aliases are no longer resolved as Vitest does not resolve tsconfig paths by default. In the reproduction, simply running pnpm nuxt test
will result in the error Error: Cannot find module '~/utils/add'
.
The older defineVitestConfig
added the necessary Nuxt alias resolutions by default, as does the new defineVitestProject
, but the recommended project config for non-nuxt
environment tests does not have the necessary resolutions for aliases to work. This complicates the process for users migrating from defineVitestConfig
to defineVitestProject
, and results in unintuitive errors for new users who prefer/use aliases over relative paths (e.g. for readability reasons).
Some possible solutions to this issue:
- Document the need to copy relevant tsconfig paths from the generated Nuxt tsconfig to
vitest.config.ts
a. I would recommend against this solution as it is repeating information that is already stored somewhere else, and doubles the work of setting up extra tsconfig aliases if people need it in their tests - Recommend that people add
vite-tsconfig-paths
to their setup to get access to their tsconfig paths in their tests
a. Edit: I have been playing with this for about half a day, and I can't get this to work. If anyone manages to figure out how to makevite-tsconfig-paths
work with Nuxt 4's solution-style tsconfig, do let me know. - Provide a way for users to generate Vitest projects with the necessary resolutions in projects where the environment is not
nuxt
, e.g. extendingdefineVitestProject
to handle non-nuxt
environments
Additional context
No response