getVitestConfigFromNuxt returns empty viteConfig on Nuxt 4.6 + Vite 8 (rolldown) — nuxt environment tests fail with Missing "#app/..." specifier
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- nodejs, typescript
- 领域
- build-system, testing
调研方向
Start with getVitestConfigFromNuxt and startNuxtAndGetViteConfig in @nuxt/test-utils (config.mjs), which capture the config through the vite:configResolved hook. Run the repro script from the issue against a Nuxt 4.6 fixture to confirm the captured config is empty, then check how Nuxt's Vite 8 builder now exposes per-environment configs. Done when viteConfig.resolve.alias contains #app and #build, and a trivial nuxt environment test imports successfully.
由索引模型根据 Issue 内容生成。
描述
Environment
- Nuxt: 4.6.0
- Vite: 8.3.4 (rolldown-vite)
- Vitest: 4.1.11
- @nuxt/test-utils: 4.3.4 (latest; also reproduced on 4.3.2)
- Node: 22.23.4
- OS: Linux
Description
On Nuxt 4.6 + Vite 8 (rolldown), getVitestConfigFromNuxt captures an empty object as the Vite config. As a result, #app/#build aliases and Nuxt's virtual-module plugins are never registered in the test Vite server, and every test file using the nuxt environment fails at import time:
Error: Missing "#app/composables/router" specifier in "@nuxt/test-utils" package
Plugin: vite:import-analysis
(#app/... falls through to package-imports resolution of @nuxt/test-utils because no alias matched.)
Minimal reproduction
// repro.mjs — run from any Nuxt 4.6 project root
const mod = await import('@nuxt/test-utils/dist/config.mjs')
const cfg = await mod.getVitestConfigFromNuxt(undefined, { overrides: { rootDir: process.cwd() } })
console.log('viteConfig keys:', Object.keys(cfg.viteConfig || {}))
console.log('resolve.alias present:', !!cfg.viteConfig?.resolve?.alias)
Expected: viteConfig contains Nuxt's client Vite config, including resolve.alias with #app, #build, ~, etc.
Actual:
viteConfig keys: []
resolve.alias present: false
Also reproduced with nitroEnvironment: true, and with both the app root and a minimal fixture (rootDir override). Reproduced with any trivial nuxt environment test file, e.g.:
// test/probe.test.ts
import { it } from 'vitest'
import { useNuxtApp } from '#app'
it('probe', () => { console.log(Object.keys(useNuxtApp())) })
// vitest.config.ts
import { defineVitestConfig } from '@nuxt/test-utils/config'
export default defineVitestConfig({ test: {} })
Analysis
getVitestConfigFromNuxt captures the config via the vite:configResolved hook (startNuxtAndGetViteConfig). With Nuxt 4.6's Vite 8 builder (@nuxt/vite-builder), the hook fires but the captured config has zero keys. Nuxt 4.6's builder now constructs per-environment configs (environments.client / environments.ssr, see vite-builder clientEnvironment() and the strippedConfig hook invocation in the build path), so the top-level Vite config shape test-utils expects appears to have moved.
Happy to provide more diagnostics if useful.
- 主要语言
- TypeScript
- 星标
- 445
- 派生
- 121
- 平均合并
- 3 天 11 小时
- 30 天内合并 PR
- 23
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nuxt/test-utils 的其他 Issue
-
nuxt environment: `fetch(new Request(url))` fails with `Failed to parse URL from [object Request]`可能已有人在做 @yamachi4416 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 35/100
nuxt/test-utils#1891 ·
维护者通常 2 天内回复
-
难度 3/5 1-2 天 新手友好度 76/100
nuxt/test-utils#1889 · 1 条评论 ·
维护者通常 2 天内回复
-
pending triage
难度 3/5 1-2 天 新手友好度 55/100
nuxt/test-utils#1671 · 5 条评论 · 1 个 reaction ·
维护者通常 2 天内回复
-
pending triage
难度 4/5 3-5 天 新手友好度 52/100
nuxt/test-utils#1607 · 2 条评论 ·
维护者通常 2 天内回复
-
`@vitest-environment-options` is not working可能已有人在做 @yamachi4416 于 210 天前认领。 未关闭pending triage
难度 3/5 1-2 天 新手友好度 45/100
nuxt/test-utils#1541 · 2 个 reaction ·
维护者通常 2 天内回复
相似的 Issue
-
bug priority: low role: BE stage: now
难度 2/5 1-3 小时 新手友好度 86/100
ahmadrosid/nakama#2594 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
milind-soni/OpenMausBot#6495 ·
维护者通常 1 天内回复
-
Navigating the session tree adds the branch's prompts to Up-arrow history again可能已有人在做 @acmerfight 今天认领。 未关闭untriaged
难度 2/5 1-3 小时 新手友好度 68/100
earendil-works/pi#12279 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
approved documentation
难度 1/5 1 小时以内 新手友好度 89/100
vitest-dev/vitest#12015 · 4 条评论 ·
维护者通常 1 天内回复