René's URL Explorer Experiment


Title: karma builder: component imported through a barrel is undefined in TestBed when another spec has an async test (cross-chunk lazy init, karma counterpart of #33728) · Issue #34250 · angular/angular-cli · GitHub

Open Graph Title: karma builder: component imported through a barrel is undefined in TestBed when another spec has an async test (cross-chunk lazy init, karma counterpart of #33728) · Issue #34250 · angular/angular-cli

X Title: karma builder: component imported through a barrel is undefined in TestBed when another spec has an async test (cross-chunk lazy init, karma counterpart of #33728) · Issue #34250 · angular/angular-cli

Description: Which @angular/* package(s) are the source of the bug? build Is this a regression? No Description With the @angular/build:karma builder (esbuild), a standalone component imported through a barrel (export * from './x') can be undefined in...

Open Graph Description: Which @angular/* package(s) are the source of the bug? build Is this a regression? No Description With the @angular/build:karma builder (esbuild), a standalone component imported through a barrel (...

X Description: Which @angular/* package(s) are the source of the bug? build Is this a regression? No Description With the @angular/build:karma builder (esbuild), a standalone component imported through a barrel (...

Opengraph URL: https://github.com/angular/angular-cli/issues/34250

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"karma builder: component imported through a barrel is undefined in TestBed when another spec has an async test (cross-chunk lazy init, karma counterpart of #33728)","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\nbuild\n\n### Is this a regression?\n\nNo\n\n### Description\n\nWith the `@angular/build:karma` builder (esbuild), a standalone component imported through a **barrel** (`export * from './x'`) can be `undefined` inside another component's `imports: [...]`. TestBed then throws `Cannot read properties of undefined (reading 'ɵcmp')`. Whether it fails depends only on **which other spec files are part of the same test bundle**. The full suite of a project can pass while a subset (`--include`) fails, or the other way around.\n\nThis looks like the karma counterpart of #33728. The mechanism is the same: shared chunks, lazy `__esm` initialisers, and a spec with an `async` test plus zone.js. #33729 fixed that one by setting `disableCodeSplitting` for the **Vitest** runner of `@angular/build:unit-test`. `src/builders/karma/application_builder.ts` on `main` still bundles with code splitting enabled, so the karma builder is still affected.\n\nWhat happens in the emitted bundle:\n\n1. A spec that contains an `async` test callback is emitted as CommonJS (`var require_x_spec = __commonJS({...}); export default require_x_spec();`). Everything it imports becomes a lazy `__esm` initialiser. Here that includes the component behind the barrel (`init_form_layout_component()`).\n2. The barrel module (`index.ts`, just `export *`) is placed in its own chunk. That chunk is what calls `init_form_layout_component()`.\n3. The chunk with the consuming component (`DialogComponent`, shared by two specs) imports the component's chunk directly, but **not** the barrel's chunk. It never calls the initialiser itself.\n4. The spec entry imports the consumer's chunk **before** the barrel's chunk. The consumer's `@Component({ imports: [FormLayoutComponent] })` decorator is evaluated while `FormLayoutComponent` is still `undefined`. The array literal keeps that `undefined` for good, even though the binding becomes defined a moment later.\n\nTrigger conditions, each toggled on its own in the reproduction below:\n\n| Condition | Without it |\n|---|---|\n| Another spec in the bundle has an `async` test and imports the component directly | removing `async` from `b/other.spec.ts`: **4/4 pass** |\n| The consumer imports the component through a barrel | importing from `../layout/form-layout.component`: passes (the consumer then calls the initialiser itself) |\n| The consumer is shared by ≥ 2 specs and the barrel by ≥ 3, so they land in different chunks | with a single consumer spec, everything is inlined and passes |\n\n### Minimal Reproduction\n\nEight small files, run with `ng test --watch=false`:\n\n**angular.json** (test target only)\n```json\n{\n  \"version\": 1,\n  \"projects\": {\n    \"repro\": {\n      \"projectType\": \"application\",\n      \"root\": \"\",\n      \"sourceRoot\": \"src\",\n      \"architect\": {\n        \"test\": {\n          \"builder\": \"@angular/build:karma\",\n          \"options\": {\n            \"polyfills\": [\"zone.js\", \"zone.js/testing\"],\n            \"tsConfig\": \"tsconfig.spec.json\",\n            \"browsers\": \"ChromeHeadless\"\n          }\n        }\n      }\n    }\n  }\n}\n```\n\n**tsconfig.json**\n```json\n{\n  \"compilerOptions\": {\n    \"strict\": true, \"skipLibCheck\": true, \"isolatedModules\": true,\n    \"experimentalDecorators\": true, \"importHelpers\": true,\n    \"target\": \"ES2022\", \"module\": \"preserve\"\n  }\n}\n```\n`tsconfig.spec.json` extends it with `\"types\": [\"jasmine\"]` and `\"include\": [\"src/**/*.ts\"]`.\n\n**src/app/layout/form-layout.component.ts**\n```ts\nimport { Component } from '@angular/core';\n\n@Component({ selector: 'app-form-layout', template: '\u003cng-content />' })\nexport class FormLayoutComponent {}\n```\n\n**src/app/layout/index.ts**\n```ts\nexport * from './form-layout.component';\n```\n\n**src/app/a/dialog.component.ts**\n```ts\nimport { Component } from '@angular/core';\nimport { FormLayoutComponent } from '../layout';\n\n@Component({\n  selector: 'app-dialog',\n  imports: [FormLayoutComponent],\n  template: '\u003capp-form-layout>dialog\u003c/app-form-layout>',\n})\nexport class DialogComponent {}\n```\n\n**src/app/a/dialog.component.spec.ts** and **src/app/a/dialog-again.spec.ts** (identical, two consumers of `DialogComponent`)\n```ts\nimport { TestBed } from '@angular/core/testing';\nimport { DialogComponent } from './dialog.component';\n\ndescribe('DialogComponent', () => {\n  it('creates', () => {\n    TestBed.configureTestingModule({ imports: [DialogComponent] });\n    expect(TestBed.createComponent(DialogComponent).componentInstance).toBeTruthy();\n  });\n});\n```\n\n**src/app/c/page.component.ts** (a third importer of the barrel) and its spec\n```ts\nimport { Component } from '@angular/core';\nimport { FormLayoutComponent } from '../layout';\n\n@Component({\n  selector: 'app-page',\n  imports: [FormLayoutComponent],\n  template: '\u003capp-form-layout>page\u003c/app-form-layout>',\n})\nexport class PageComponent {}\n```\n```ts\nimport { TestBed } from '@angular/core/testing';\nimport { PageComponent } from './page.component';\n\ndescribe('PageComponent', () => {\n  it('creates', () => {\n    TestBed.configureTestingModule({ imports: [PageComponent] });\n    expect(TestBed.createComponent(PageComponent).componentInstance).toBeTruthy();\n  });\n});\n```\n\n**src/app/b/other.spec.ts** (the only spec with an `async` test; it imports the component directly)\n```ts\nimport { TestBed } from '@angular/core/testing';\nimport { FormLayoutComponent } from '../layout/form-layout.component';\n\ndescribe('Other (has an async test)', () => {\n  it('creates the layout', async () => {\n    TestBed.configureTestingModule({ imports: [FormLayoutComponent] });\n    await Promise.resolve();\n    expect(TestBed.createComponent(FormLayoutComponent).componentInstance).toBeTruthy();\n  });\n});\n```\n\nResult: `TOTAL: 2 FAILED, 2 SUCCESS`. Both `DialogComponent` specs fail with the error below. Removing `async` (and the `await`) from `other.spec.ts` gives `TOTAL: 4 SUCCESS`.\n\n### Exception or Error\n\n```text\nTypeError: Cannot read properties of undefined (reading 'ɵcmp')\n    at getComponentDef2\n    at isStandaloneComponent\n    at queueTypesFromModulesArrayRecur\n    at TestBedCompiler.queueTypesFromModulesArray\n    at TestBedCompiler.configureTestingModule\n    at _TestBedImpl.configureTestingModule\n```\n\n### Your Environment\n\n```text\nAngular CLI: 20.3.32\nNode: 24.12.0\nPackage Manager: npm 11.6.2\nOS: darwin arm64\n\nAngular: 20.3.16\n@angular/build 20.3.16 (esbuild 0.25.9)\ntypescript 5.8.3\nzone.js 0.15.1\n```\n\n### Anything else relevant?\n\n- I reproduced it on 20.3.16. I haven't run it on 22.x, but on `main` the karma builder still doesn't set `disableCodeSplitting` (only `unit-test/runners/vitest/build-options.ts` does since #33729). The code path looks unchanged.\n- In a real project this showed up as 3–5 component specs failing only when `--include` mixed two folders, while the full suite passed. Which spec happened to call the initialiser first decided the outcome.\n- Applying the same `disableCodeSplitting: true` to the karma application build seems like the natural fix, as #33729 did for Vitest.\n","author":{"url":"https://github.com/fabiofigrod","@type":"Person","name":"fabiofigrod"},"datePublished":"2026-10-03T21:59:03Z","url":"https://github.com/angular/angular-cli/issues/34250"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:204d325d-1aa9-d6f8-1cf2-01119f258967
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE522:1D20B7:2B47AF0:36DE903:6B01E0F1
html-safe-nonce81001a0f347656284a477127e5d68d0214fa608da794e69f515a42d12e89a75b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTIyOjFEMjBCNzoyQjQ3QUYwOjM2REU5MDM6NkIwMUUwRjEiLCJ2aXNpdG9yX2lkIjoiODAxODk1MDc0NTEzMzAxNTI4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacfd1952cb9b1b0f8e87d67c09691c794f39802e801427b7ff29b1a529c1728694
hovercard-subject-tagissue:5693885025
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/34250/issue_layout
twitter:imagehttps://opengraph.githubassets.com/9432fda4dad65a7b6e4dfe66b3a591509455fa549b7d2d38b8e29728f535e371/angular/angular-cli/issues/34250
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/9432fda4dad65a7b6e4dfe66b3a591509455fa549b7d2d38b8e29728f535e371/angular/angular-cli/issues/34250
og:image:altWhich @angular/* package(s) are the source of the bug? build Is this a regression? No Description With the @angular/build:karma builder (esbuild), a standalone component imported through a barrel (...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamefabiofigrod
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/angular/angular-cli git https://github.com/angular/angular-cli.git
octolytics-dimension-user_id139426
octolytics-dimension-user_loginangular
octolytics-dimension-repository_id36891867
octolytics-dimension-repository_nwoangular/angular-cli
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id36891867
octolytics-dimension-repository_network_root_nwoangular/angular-cli
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/angular/angular-cli/issues/34250#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular-cli%2Fissues%2F34250
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular-cli%2Fissues%2F34250
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=angular%2Fangular-cli
Reloadhttps://github.com/angular/angular-cli/issues/34250
Reloadhttps://github.com/angular/angular-cli/issues/34250
Reloadhttps://github.com/angular/angular-cli/issues/34250
angularhttps://github.com/angular
angular-clihttps://github.com/angular/angular-cli
Codehttps://github.com/angular/angular-cli
Issues198 (198)https://github.com/angular/angular-cli/issues
Pull requests23 (23)https://github.com/angular/angular-cli/pulls
Actionshttps://github.com/angular/angular-cli/actions
Security and quality8 (8)https://github.com/angular/angular-cli/security
Insightshttps://github.com/angular/angular-cli/insights
https://github.com/angular/angular-cli
New issuehttps://github.com/login?return_to=https://github.com/angular/angular-cli/issues/34250
New issuehttps://github.com/login?return_to=https://github.com/angular/angular-cli/issues/34250
karma builder: component imported through a barrel is undefined in TestBed when another spec has an async test (cross-chunk lazy init, karma counterpart of #33728)https://github.com/angular/angular-cli/issues/34250#top
area: @angular/buildhttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22area%3A%20%40angular%2Fbuild%22
needsTriagehttps://github.com/angular/angular-cli/milestone/11
https://github.com/fabiofigrod
fabiofigrodhttps://github.com/fabiofigrod
on Oct 3, 2026https://github.com/angular/angular-cli/issues/34250#issue-5693885025
#33728https://github.com/angular/angular-cli/issues/33728
#33729https://github.com/angular/angular-cli/pull/33729
fix(@angular/build): disable code splitting for unit test builds #33729https://github.com/angular/angular-cli/pull/33729
fix(@angular/build): disable code splitting for unit test builds #33729https://github.com/angular/angular-cli/pull/33729
angular-robothttps://github.com/apps/angular-robot
area: @angular/buildhttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22area%3A%20%40angular%2Fbuild%22
on Oct 3, 2026https://github.com/angular/angular-cli/issues/34250#event-32416501444
angular-robothttps://github.com/apps/angular-robot
needsTriagehttps://github.com/angular/angular-cli/milestone/11
on Oct 3, 2026https://github.com/angular/angular-cli/issues/34250#event-32416502188
https://github.com/nagahara-naoki
nagahara-naokihttps://github.com/nagahara-naoki
on Nov 7, 2026https://github.com/angular/angular-cli/issues/34250#issuecomment-6708048766
https://github.com/nagahara-naoki
nagahara-naokihttps://github.com/nagahara-naoki
on Nov 7, 2026https://github.com/angular/angular-cli/issues/34250#issuecomment-6708359331
#34668https://github.com/angular/angular-cli/pull/34668
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular-cli/issues/34250
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular-cli/issues/34250
area: @angular/buildhttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22area%3A%20%40angular%2Fbuild%22
needsTriageNo due datehttps://github.com/angular/angular-cli/milestone/11
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.