Skip to content

fix(@angular/build): resolve unimported NgModule scopes when filtering unit-test files - #34329

Merged
dgp1130 merged 1 commit into
angular:mainfrom
clydin:fix/unit-test-ngmodule-scope-fallback
Oct 14, 2026
Merged

dgp1130 merged 1 commit into
angular:mainfrom
clydin:fix/unit-test-ngmodule-scope-fallback

Conversation

@clydin

@clydin clydin commented Oct 13, 2026

Copy link
Copy Markdown
Member

When rootFiles overrides are provided (such as during unit-test runs), the initial TypeScript program is restricted to those entry points and their transitive imports. If a test imports a non-standalone @Component directly without importing its declaring @NgModule, the NgModule may be omitted from the program and leave the component without its compilation scope.

Preserve the full tsconfig root file set as fallbackRootNames for application builds when rootFiles is a subset of the tsconfig files. If AOT analysis detects a non-standalone component lacking an owning NgModule scope (getOwningNgModule(component) === null) and additional uncompiled tsconfig files exist, recreate and re-analyze the Angular program with the full root file set so all NgModule declarations can be discovered.

…g unit-test files

When `rootFiles` overrides are provided (such as during `unit-test` runs),
the initial TypeScript program is restricted to those entry points and their
transitive imports. If a test imports a non-standalone `@Component` directly
without importing its declaring `@NgModule`, the `NgModule` may be omitted
from the program and leave the component without its compilation scope.

Preserve the full `tsconfig` root file set as `fallbackRootNames` for
application builds when `rootFiles` is a subset of the `tsconfig` files. If
AOT analysis detects a non-standalone component lacking an owning `NgModule`
scope (`getOwningNgModule(component) === null`) and additional uncompiled
`tsconfig` files exist, recreate and re-analyze the Angular program with the
full root file set so all `NgModule` declarations can be discovered.
@clydin
clydin force-pushed the fix/unit-test-ngmodule-scope-fallback branch from 6be51ea to 957de2a Compare October 13, 2026 16:56
@clydin
clydin marked this pull request as ready for review October 13, 2026 18:47

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a fallback mechanism to the full tsconfig root file set (fallbackRootNames) during AOT compilation when explicit rootFiles filtering is active. This fallback is triggered if a non-standalone component is encountered that lacks a resolved NgModule scope, allowing the Angular compiler to discover all NgModules and resolve component compilation scopes. Unit tests have been added to verify this behavior. I have no additional feedback to provide as there are no review comments.

@clydin clydin added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Oct 13, 2026
@alan-agius4 alan-agius4 linked an issue Oct 13, 2026 that may be closed by this pull request
1 task done
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 14, 2026
@dgp1130
dgp1130 merged commit 7714a85 into angular:main Oct 14, 2026
43 of 44 checks passed
@dgp1130

dgp1130 commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

@clydin
clydin deleted the fix/unit-test-ngmodule-scope-fallback branch October 14, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ng test fails with NG8001 in a new NgModule app on 22.2.0

3 participants