Vitest coverage issue `vite:import-analysis` error `Pre-transform error: Failed to resolve import "#/util" from "src/app/app.ts". Does the file exist?`
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- playwright, typescript
- 領域
- testing-qa
調査の方向性
まず、記載された Angular プロジェクト、tsconfig.json のパスエイリアス、src/app/app.ts の import、および ng test コマンドを使って失敗を再現し、Vitest 4.1.0 と 4.0.8 を比較します。共有 app chunk がエイリアスを参照する場合の coverage 生成と source-map の処理を追跡します。エイリアスが解決された状態で、vite:import-analysis エラーなしにブラウザの coverage が完了すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Command
test
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
vitest@4.0.8
Description
I'm not sure if this issue is an issue with Vitest, or the Angular CLI integration with Vitest. I put the issue here, because I have no idea how to reproduce this issue without Angular at the moment.
The issue is that when using tsconfig.json property paths and running browser tests with coverage, these paths will not used when Vitest tries to read coverage from source maps. The requirement seems to be that a shared chunk exists (import './app' in the repro steps).
This results in errors during coverage generation, but tests do not crash. The errors come from Vite's dev server pre transforming original .ts files referenced in source-maps.
Requirements
- Using
pathsintsconfig.json - Angular CLI +
eslintcreates a shared chunk that has thepathsin it's sourcemap - Vitest with
browsers+coverage+coverageInclude - Vitest
v4.1.0+
Minimal Reproduction
- Init Angular project & install vitest coverage & browser packages
npx @angular/cli@21.1.5 new ng21.1.5 -s -t --style css --no-ssr --ai-config none
npm i -E -D vitest@4.1.0 @vitest/browser-playwright@4.1.0 @vitest/coverage-v8@4.1.0 playwright
- Add
src/app/util.tsfile
export const greet = 'Hello';
- Add a path alias to util file
{
"compilerOptions": {
"paths": {
"#/util": ["./src/app/util.ts"]
}
}
}
- Make
App(app.ts) use value fromutil.ts
import { greet } from '#/util';
// ...
export class App {
protected readonly title = signal(greet);
}
- Add import to
app.tsfromapp.config.ts
import './app';
- Run tests with browser, coverage & coverage include
npx ng test --no-watch --browsers chromium --coverage --coverage-include src/app/**/*.ts
Exception or Error
There's logged errors for every file that uses the path alias, which in our project is most of them (e.g. `import { shared } from '#/core';`).
00:02:12 [vite] (client) Pre-transform error: Failed to resolve import "#/util" from "src/app/app.ts". Does the file exist?
Plugin: vite:import-analysis
File: C:/Users/foo/repro/src/app/app.ts:3:22
11 | import { Component, signal } from "@angular/core";
12 | import { RouterOutlet } from "@angular/router";
13 | import { greet } from "#/util";
| ^
14 | export let App = class {
15 | title = signal(greet);
Your Environment
I've tried with `@angular/build` + `@angular/cli` at several versions, including `21.1.x` and `21.2.x`. Downgrading `vitest` to `4.0.8` fixes the issue, but `vitest@4.1.0` and `4.1.2` both failed.
----------------------------------------
Angular CLI : 21.2.5
Angular : 21.2.6
Node.js : 25.8.2 (Unsupported)
Package Manager : npm 11.11.1
Operating System : win32 x64
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build │ 21.2.5 │ ^21.1.5 │
│ @angular/cli │ 21.2.5 │ ^21.1.5 │
│ @angular/common │ 21.2.6 │ ^21.1.0 │
│ @angular/compiler │ 21.2.6 │ ^21.1.0 │
│ @angular/compiler-cli │ 21.2.6 │ ^21.1.0 │
│ @angular/core │ 21.2.6 │ ^21.1.0 │
│ @angular/forms │ 21.2.6 │ ^21.1.0 │
│ @angular/platform-browser │ 21.2.6 │ ^21.1.0 │
│ @angular/router │ 21.2.6 │ ^21.1.0 │
│ rxjs │ 7.8.2 │ ~7.8.0 │
│ typescript │ 5.9.3 │ ~5.9.2 │
│ vitest │ 4.1.0 │ 4.1.0 │
└───────────────────────────┴───────────────────┴───────────────────┘
Anything else relevant?
Does not seem to be OS specific. The issue is on GitHub Actions on Ubuntu, and locally on Windows.
- 主要言語
- TypeScript
- スター
- 27k
- フォーク
- 11.8k
- 平均マージ
- 16時間 21分
- マージ済み PR(30日)
- 170
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
angular/angular-cli のほかの issue
-
area: @angular/build gemini-triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
angular/angular-cli#33955 ·
-
area: @angular/cli gemini-triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
angular/angular-cli#33055 · コメント 1 件 · リアクション 3 件 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34131 · 担当者 1 名 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34130 · 担当者 1 名 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34128 · 担当者 1 名 ·
angular/angular-cli の issue をすべて見る
似ている issue
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
-
Ecosystem: ClawMetry — the Qwen Code reader is now free and open source (follow-up to #9294 / #9338) オープンcategory/integration priority/P3 scope/documentation status/ready-for-human type/feature-request
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
-
area:auth FE mvp P3
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
klasolsson81/jobbliggaren#1788 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
get-convex/migrations#69 ·
-
accessibility angular bug good first issue typescript ux
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
apache/fineract-backoffice-ui#584 · コメント 1 件 ·