Skip to content

fix(@angular/build): show clear error when styleUrl points to a TypeScript file#32881

Merged
dgp1130 merged 1 commit intoangular:mainfrom
maruthang:fix-32193-styleurl-ts-error
Apr 8, 2026
Merged

fix(@angular/build): show clear error when styleUrl points to a TypeScript file#32881
dgp1130 merged 1 commit intoangular:mainfrom
maruthang:fix-32193-styleurl-ts-error

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

PR Checklist

PR Type

  • Bugfix

What is the current behavior?

When a component's styleUrl accidentally points to a .ts file, the TypeScript content is fed to the CSS parser, producing confusing downstream errors (e.g., rxjs-related "Could not resolve" errors) that don't indicate the actual problem.

Issue Number: #32193

What is the new behavior?

TypeScript files (.ts, .tsx, .mts, .cts) used as component resources are now rejected early in resourceNameToFileName() in the Angular compiler host. The function returns null, causing the Angular compiler to emit a clear "Could not find stylesheet file './app.component.ts'" error that directly points to the problem.

This follows the existing hasTemplateExtension() pattern in the same file.

Does this PR introduce a breaking change?

  • Yes
  • No

Copy link
Copy Markdown

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

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 prevents TypeScript files from being used as component resources by adding a check in the Angular compiler host and a corresponding test case. The reviewer suggested refactoring the extension check logic to use Array.prototype.includes() for better readability and conciseness.

…cript file

Reject TypeScript files (.ts, .tsx, .mts, .cts) used as component
resources in the Angular compiler host. Previously this caused confusing
downstream errors (e.g., rxjs-related). Now the file is treated as not
found, producing a clear 'Could not find stylesheet file' message.

Fixes angular#32193
@alan-agius4 alan-agius4 force-pushed the fix-32193-styleurl-ts-error branch from 9f404e4 to 5fedfc0 Compare April 8, 2026 16:23
Copy link
Copy Markdown
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Apr 8, 2026
@dgp1130 dgp1130 merged commit e2f95fc into angular:main Apr 8, 2026
37 checks passed
@dgp1130
Copy link
Copy Markdown
Collaborator

dgp1130 commented Apr 8, 2026

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

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: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants