Meta tags:
description= PR Checklist
Please check to confirm your PR fulfills the following requirements:
The commit message follows our guidelines: htt????/github.com/angular/angular-cli/blob/main/CONTRIBUTING.md#-commit-message-guidelines
Tests for the changes have been added (for bug fixes / features)
Docs have been added / updated (for bug fixes / features)
PR Type
What kind of change does this PR introduce?
Bugfix
Feature
Code style update (formatting, local variables)
Refactoring (no functional changes, no api changes)
Build related changes
CI related changes
Documentation content changes
Other... Please describe:
What is the current behavior?
When a project configures compilerOptions.paths in tsconfig.json (e.g.
#/* : [ ./src/app/* ]) and runs ng test with coverage: true, Vitest s
vite:import-analysis plugin fails during the coverage phase with:
Pre-transform error: Failed to resolve import #/util from src/app/app.ts .
Does the file exist?
This happens because the Angular CLI s Vitest integration does not forward
tsconfig path aliases to Vite s resolve.alias configuration. They are
resolved during compilation (by esbuild) but not during Vitest s own
Vite-based coverage instrumentation pass.
Issue Number: #32891
What is the new behavior?
The tsconfig file is read at Vitest initialisation time. Its
compilerOptions.paths entries are converted to Vite-compatible
resolve.alias objects (supporting both exact and wildcard patterns) and
injected into the projectDefaults.resolve.alias config that the Angular
CLI passes to the Vitest project workspace.
Path aliases are now resolved correctly during both test execution and
coverage instrumentation.
Does this PR introduce a breaking change?
Yes
No
Other information
The fix is intentionally narrow — it only reads paths and baseUrl from
the tsconfig, leaving all other resolution behaviour unchanged. Comment
syntax in tsconfig files (C-style /* */ and //) is stripped before
JSON parsing to handle real-world configs.
A new behavior spec (vitest-coverage-tsconfig-paths_spec.ts) verifies the
fix end-to-end using the builder test harness.;
Headings (most frequently used words):
uh, oh, for, navigation, fix, angular, build, forward, tsconfig, paths, as, vite, aliases, vitest, coverage, 33024, are, footer, you, gemini, code, assist, bot, apr, 20, 2026, choose, reason, hiding, this, comment, diff, view, menu, repository, there, no, files, selected, viewing, sure, want, to, change, the, base, filter, by, extension,
Text of the page (most frequently used words):
file (29), this (27), the (23), #tsconfig (23), #angular (21), and (20), path (19), for (19), const (18), github (17), src (17), that (16), paths (15), vitest (15), coverage (14), util (14), string (14), build (14), line (13), json (13), app (13), from (12), all (12), loading (12), return (12), applied (11), reload (11), aliases (11), comment (11), code (10), test (10), import (10), show (10), characters (10), you (9), while (9), there (9), was (9), harness (9), vite (9), alias (9), hidden (9), unicode (9), open (9), comments (8), change (8), await (8), diff (8), join (8), can (7), suggestion (7), cannot (7), please (7), suggestions (7), changes (7), error (7), resolve (7), async (7), component (7), learn (7), builders (7), unit (7), expand (7), tsconfigpath (7), target (7), basedir (7), replacement (7), find (7), replace (7), sign (7), not (6), page (6), function (6), number (6), bidirectional (6), may (6), more (6), pattern (6), targetdir (6), reason (6), files (6), packages (6), security (5), commit (5), appcomponent (5), export (5), compileroptions (5), behavior (5), review (5), about (5), view (5), regexp (5), hide (5), quality (5), choose (5), runners (5), fix (5), base (5), your (5), 2026 (4), pull (4), resolved (4), outdated (4), add (4), analysis (4), imports (4), describe (4), parse (4), with (4), license (4), original (4), contains (4), what (4), options (4), prefix (4), escaperegexp (4), new (4), hiding (4), copy (4), rawbaseurl (4), raw (4), are (4), load (4), forward (4), commits (4), support (4), copilot (4), community (3), navigation (3), request (3), batch (3), something (3), went (3), wrong (3), retry (3), failed (3), testbed (3), spec (3), writefile (3), write (3), greet (3), content (3), module (3), will (3), during (3), https (3), source (3), style (3), text (3), interpreted (3), compiled (3), differently (3), than (3), appears (3), below (3), editor (3), reveals (3), desktop (3), delete (3), edit (3), tests (3), paths_spec (3), additions (3), deletions (3), down (3), tsconfigaliases (3), main (3), toposixpath (3), exact (3), issues (3), apr (3), targets (3), regex (3), cli (3), its (3), plugins (3), executor (3), whitespace (3), filter (3), 33024 (3), tomeelog (3), branch (3), refname (3), account (3), another (3), tab (3), window (3), refresh (3), session (3), developers (3), changelog (3), customer (3), enterprise (3), grade (3), features (3), contact (2), status (2), privacy (2), terms (2), footer (2), merge (2), create (2), valid (2), lines (2), single (2), one (2), viewing (2), were (2), toggle (2), index (2), expect (2), result (2), when (2), used (2), any (2), eslint (2), next (2), true (2), base_options (2), fixture (2), should (2), beforeeach (2), core (2), greeting (2), class (2), via (2), name (2), setupapplicationtarget (2), describebuilder (2), execute (2), unit_test_builder_info (2), found (2), use (2), length (2), es2020 (2), browser (2), createvitestconfigplugin (2), readtsconfigpathaliases (2), reactions (2), sorry (2), suggested (2), across (2), posix (2), absolute (2), low (2), duplicate (2), off (2), topic (2), abuse (2), spam (2), displayed (2), others (2), problem (2), markdown (2), link (2), bot (2), gemini (2), assist (2), thread (2), entries (2), strings (2), accounts (2), them (2), see (2), str (2), watch (2), include (2), 378 (2), selected (2), apply (2), split (2), unified (2), jump (2), extension (2), tree (2), old (2), default (2), could (2), tags (2), branches (2), issue (2), insights (2), actions (2), 196 (2), repository (2), signed (2), universe (2), training (2), integrations (2), stories (2), center (2), documentation (2), business (2), fixes (2), products (2), secret (2), perform, action, time, share, personal, information, manage, cookies, docs, inc, right, now, check, back, later, queued, multi, pending, reviews, has, been, marked, must, existing, order, applying, deleted, supported, only, per, subset, closed, invalid, because, made, annotations, notes, oops, expectfile, html, toexist, success, tobetrue, executeonce, present, enabled, regression, throw, pre, transform, coveragereporters, disable, typescript, explicit, usetarget, componentinstance, tobetruthy, createcomponent, compilecomponents, configuretestingmodule, testing, exercises, hence, transitively, world, standalone, template, selector, root, stringify, null, modifyfile, hello, utility, imported, instrumentation, setup, dev, governed, mit, copyright, google, llc, rights, reserved, ngular, conditions, es2015, mainfields, 179, 236, setupfiles, projectdefaults, userworkspaceconfig, projectresolver, createrequire, projectsourceroot, 164, 217, findtestenvironment, catch, ensure, consistent, different, operating, systems, especially, windows, recommended, normalize, format, using, generally, prefer, correctly, formatted, mixing, slashes, lead, resolution, 105, slice, wildcard, endswith, object, flatmap, dirname, isabsolute, baseurl, record, current, stripping, prone, breaking, example, urls, like, patterns, safer, approach, avoid, accidental, matches, within, contain, strip, before, parsing, readfile, utf, try, promise, com, 32891, where, resolves, honoured, processing, compatible, ensures, such, reads, converts, escapes, special, inside, does, fail, provided, forwarded, boolean, optimizedepsinclude, interface, vitestconfigpluginoptions, undefined, workspaceroot, projectplugins, vitestexecutor, implements, testexecutor, conversations, clear, filters, viewed, type, nbsp, vites, 008fc74, select, changed, checks, conversation, wants, into, some, removed, timeline, become, sure, want, nothing, already, clicking, agree, our, occasionally, send, related, emails, statement, service, free, maintainers, have, question, project, items, requests, message, dismiss, alert, switched, out, appearance, settings, search, pricing, event, talks, workshops, partners, company, forum, events, webinars, blog, resource, connect, resources, premium, advanced, ons, trust, why, evaluate, industries, government, manufacturing, financial, services, healthcare, industry, nonprofits, startups, team, enterprises, stage, businesses, latest, improvements, place, developer, articles, sponsors, trending, repos, explore, customize, certifications, scanning, leak, prevention, protection, vulnerability, detection, remediation, secure, cloud, development, environments, codespaces, enforcement, automation, ship, coding, agent, tasks, projects, automated, work, hosting, collaboration, platform, menu, skip,
Text of the page (random words):
fix angular build forward tsconfig paths as vite aliases for vitest coverage by tomeelog pull request 33024 angular angular cli github skip to content navigation menu sign in products platform github repository hosting code review and collaboration copilot ai coding agent for tasks projects and automated work build ship actions ci cd and automation code quality quality analysis fixes and enforcement codespaces cloud development environments secure code security vulnerability detection and remediation secret protection secret scanning and leak prevention all features developers learn documentation training certifications build build with copilot customize copilot integrations explore trending repos github sponsors developer articles changelog changelog your source for the latest features improvements and fixes across github products all in one place businesses by stage enterprises team startups nonprofits by industry healthcare financial services manufacturing government see all industries evaluate github why github customer stories business insights trust center add ons github advanced security enterprise grade code security copilot for business enterprise grade ai features premium support enterprise grade 24 7 support resources learn connect documentation resource center blog events webinars community forum customer stories integrations support customer support training github status company about partners changelog github universe github universe the event for developers by developers talks workshops and what s next for github pricing search sign in sign up appearance settings you signed in with another tab or window reload to refresh your session you signed out in another tab or window reload to refresh your session you switched accounts on another tab or window reload to refresh your session dismiss alert message angular angular cli repository navigation code issues 196 196 pull requests 20 20 actions security and quality 8 8 insights more items fix angular build forward tsconfig paths as vite aliases for vitest coverage 33024 new issue have a question about this project sign up for a free github account to open an issue and contact its maintainers and the community sign up for github by clicking sign up for github you agree to our terms of service and privacy statement we ll occasionally send you account related emails already on github sign in to your account open tomeelog wants to merge 1 commit into angular main base main choose a base branch branches tags could not load branches branch not found refname loading refname default could not load tags nothing to show refname default loading are you sure you want to change the base some commits from the old base branch may be removed from the timeline and old review comments may become outdated loading change base from tomeelog fix vitest coverage tsconfig paths conversation 3 commits 1 checks 7 files changed uh oh there was an error while loading please reload this page open fix angular build forward tsconfig paths as vite aliases for vitest coverage 33024 show file tree hide file tree changes from all commits commits show all changes 1 commit select commit 008fc74 fix angular build forward tsconfig paths as vite aliases for vites apr 20 2026 file filter filter by extension filter by extension ts nbsp 3 all 1 file type selected viewed files clear filters conversations failed to load comments retry loading uh oh there was an error while loading please reload this page jump to jump to file failed to load files retry loading uh oh there was an error while loading please reload this page diff view unified split hide whitespace apply and reload show whitespace diff view unified split hide whitespace apply and reload packages angular build src builders unit test runners vitest packages angular build src builders unit test runners vitest executor ts executor ts packages angular build src builders unit test runners vitest plugins ts plugins ts tests behavior packages angular build src builders unit test tests behavior vitest coverage tsconfig paths_spec ts vitest coverage tsconfig paths_spec ts there are no files selected for viewing 3 changes 3 additions 0 deletions 3 packages angular build src builders unit test runners vitest executor ts show comments view file edit file delete file open in desktop this file contains hidden or bidirectional unicode text that may be interpreted or compiled differently than what appears below to review open the file in an editor that reveals hidden unicode characters learn more about bidirectional unicode characters show hidden characters original file line number diff line number diff line change expand up 378 6 378 9 export class vitestexecutor implements testexecutor projectplugins include watch tsconfigpath this options tsconfig path join workspaceroot this options tsconfig undefined expand down 58 changes 58 additions 0 deletions 58 packages angular build src builders unit test runners vitest plugins ts show comments view file edit file delete file open in desktop this file contains hidden or bidirectional unicode text that may be interpreted or compiled differently than what appears below to review open the file in an editor that reveals hidden unicode characters learn more about bidirectional unicode characters show hidden characters original file line number diff line number diff line change expand up 54 6 54 59 interface vitestconfigpluginoptions include string optimizedepsinclude string watch boolean absolute path to the tsconfig file when provided its paths are forwarded as vite resolve aliases so that import analysis during coverage does not fail to resolve tsconfig path aliases e g util tsconfigpath string escapes special regex characters in a string so it can be used inside a regexp function escaperegexp str string string return str replace g reads a tsconfig file and converts its compileroptions paths entries to vite compatible resolve aliases this ensures that path aliases such as util src util are honoured during vitest coverage processing where vite import analysis re resolves imports from the original source files see https github com angular angular cli issues 32891 async function readtsconfigpathaliases tsconfigpath string promise find string regexp replacement string try const raw await readfile tsconfigpath utf 8 tsconfig files may contain c style comments strip them before parsing const json json parse raw replace s s n g comment thread gemini code assist bot apr 20 2026 copy link copy markdown there was a problem hiding this comment choose a reason for hiding this comment the reason will be displayed to describe this comment to others learn more choose a reason spam abuse off topic outdated duplicate resolved low quality hide comment the current regex for stripping comments is prone to breaking valid json if it contains strings with or for example urls like https angular io or path patterns a safer approach is to use a regex that accounts for strings to avoid accidental matches within them suggested change const json json parse raw replace s s n g const json json parse raw replace s s g m g1 g1 sorry something went wrong uh oh there was an error while loading please reload this page all reactions const paths record string string json compileroptions paths const rawbaseurl string json compileroptions baseurl const basedir path isabsolute rawbaseurl rawbaseurl path join path dirname tsconfigpath rawbaseurl return object entries paths flatmap pattern targets if targets length return const target targets 0 if pattern endswith wildcard alias app src app const prefix pattern slice 0 2 const targetdir path join basedir target replace return find new regexp escaperegexp prefix replacement targetdir 1 exact alias util src util return find pattern replacement path join basedir target comment thread comment on lines 98 to 105 gemini code assist bot apr 20 2026 copy link copy markdown there was a problem hiding this comment choose a reason for hiding this comment the reason will be displayed to describe this comment to others learn more choose a reason spam abuse off topic outdated duplicate resolved low quality hide comment to ensure consistent behavior across different operating systems especially on windows it is recommended to normalize the resolved alias paths to posix format using toposixpath vite and vitest generally prefer posix style paths or correctly formatted absolute paths for aliases and mixing slashes e g c path to file can lead to resolution issues suggested change const targetdir path join basedir target replace return find new regexp escaperegexp prefix replacement targetdir 1 exact alias util src util return find pattern replacement path join basedir target const targetdir toposixpath path join basedir target replace return find new regexp escaperegexp prefix replacement targetdir 1 exact alias util src util return find pattern replacement toposixpath path join basedir target sorry something went wrong uh oh there was an error while loading please reload this page all reactions catch return async function findtestenvironment expand down expand up 164 6 217 10 export async function createvitestconfigplugin const projectresolver createrequire projectsourceroot resolve const tsconfigaliases options tsconfigpath await readtsconfigpathaliases options tsconfigpath const projectdefaults userworkspaceconfig test setupfiles expand all 179 6 236 7 export async function createvitestconfigplugin resolve mainfields es2020 module main conditions es2015 es2020 module browser browser tsconfigaliases length alias tsconfigaliases expand down 94 changes 94 additions 0 deletions 94 ngular build src builders unit test tests behavior vitest coverage tsconfig paths_spec ts show comments view file edit file delete file open in desktop this file contains hidden or bidirectional unicode text that may be interpreted or compiled differently than what appears below to review open the file in an editor that reveals hidden unicode characters learn more about bidirectional unicode characters show hidden characters original file line number diff line number diff line change 0 0 1 94 license copyright google llc all rights reserved use of this source code is governed by an mit style license that can be found in the license file at https angular dev license import execute from index import base_options unit_test_builder_info describebuilder setupapplicationtarget from setup describebuilder execute unit_test_builder_info harness describe behavior vitest coverage with tsconfig path aliases beforeeach async setupapplicationtarget harness it should resolve tsconfig path aliases during coverage instrumentation async write a utility module that will be imported via a path alias await harness writefile src app util ts export function greet name string string return hello name add a path alias util src app util to tsconfig await harness modifyfile src tsconfig spec json content const tsconfig json parse content tsconfig compileroptions tsconfig compileroptions paths app return json stringify tsconfig null 2 write an app component that imports via the alias await harness writefile src app app component ts import component from angular core import greet from util component selector app root template h1 greeting h1 standalone true export class appcomponent greeting greet world write a spec that exercises the component and hence imports util transitively await harness writefile src app app component spec ts import testbed from angular core testing import appcomponent from app component describe appcomponent beforeeach async await testbed configuretestingmodule imports appcomponent compilecomponents it should create the app const fixture testbed createcomponent appcomponent expect fixture componentinstance tobetruthy harness usetarget test base_options coverage true eslint disable next line typescript eslint no explicit any coveragereporters json as any regression this used to throw vite import analysis pre transform error failed to resolve import when tsconfig paths were present and coverage was enabled const result await harness executeonce expect result success tobetrue harness expectfile coverage test index html toexist loading oops something went wrong retry uh oh there was an error while loading please reload this page toggle all file notes toggle all file annotations add this suggestion to a batch that can be applied as a single commit this suggestion is invalid because no changes were made to the code suggestions cannot be applied while the pull request is closed suggestions cannot be applied while viewing a subset of changes only one suggestion per line can be applied in a batch add this suggestion to a batch that can be applied as a single commit applying suggestions on deleted lines is not supported you must change the existing code in this line in order to create a valid suggestion outdated suggestions cannot be applied this suggestion has been applied or marked resolved suggestions cannot be applied from pending reviews suggestions cannot be applied on multi line comments suggestions cannot be applied while the pull request is queued to merge suggestion cannot be applied right now please check back later footer 2026 github inc footer navigation terms privacy security status community docs contact manage cookies do not share my personal information you can t perform that action at this time
|