Skip to content

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

Closed
maruthang wants to merge 1 commit intoangular:mainfrom
maruthang:fix-32193-styleurl-ts-error
Closed

fix(@angular/build): show clear error when styleUrl points to a TypeScript file#32869
maruthang wants to merge 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 instead of a stylesheet, confusing downstream errors appear (e.g., rxjs-related 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 the Angular compiler host, producing a clear "Could not find stylesheet file" error message that points to the actual problem.

Does this PR introduce a breaking change?

  • Yes
  • No

…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
@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 27, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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 incorrectly processed as component resources by the Angular compiler host, which avoids confusing downstream errors. The changes include a new validation check in the compiler host and a test case to ensure that using a TypeScript file in styleUrl triggers an error. Feedback suggests refactoring the hasTypeScriptExtension helper function to use Array.includes() for improved conciseness.

Comment on lines +277 to +289
function hasTypeScriptExtension(file: string): boolean {
const extension = nodePath.extname(file).toLowerCase();

switch (extension) {
case '.ts':
case '.tsx':
case '.mts':
case '.cts':
return true;
}

return false;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For improved readability and conciseness, you could use an array with includes() to check for the file extension. This avoids the more verbose switch statement.

function hasTypeScriptExtension(file: string): boolean {
  const extension = nodePath.extname(file).toLowerCase();

  return ['.ts', '.tsx', '.mts', '.cts'].includes(extension);
}

@maruthang maruthang deleted the fix-32193-styleurl-ts-error branch March 27, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants