Skip to content

fix(vite-plugin-angular): don't shadow Vite ?raw imports of .ts files#2359

Merged
brandonroberts merged 1 commit into
betafrom
claude/issue-2356-tXyRK
Jun 2, 2026
Merged

fix(vite-plugin-angular): don't shadow Vite ?raw imports of .ts files#2359
brandonroberts merged 1 commit into
betafrom
claude/issue-2356-tXyRK

Conversation

@brandonroberts

Copy link
Copy Markdown
Member

PR Checklist

The Angular transform filter matched query-stringed ids like foo.ts?raw via TS_EXT_REGEX
(/\.[cm]?ts(?[a-z])/, which is not anchored and ignores the query string). The id entered the
handler, the query was stripped, and Angular/esbuild recompiled the file as TypeScript — discarding
the export default "<source>" that Vite's native raw loader had already produced. As a result
import src from './file.ts?raw' failed with "default" is not exported by "….ts?raw". This broke
the documented Vite ?raw import for every .ts/.cts/.mts file (Angular component or plain
TypeScript alike), e.g. feeding a story component's source into a Storybook "Show code" panel.

Closes #2356

Affected scope

  • Primary scope: vite-plugin-angular
  • Secondary scopes: none

Recommended merge strategy for maintainer [optional]

  • Squash merge
  • Rebase merge
  • Other

What is the new behavior?

?raw-queried ids are now added to the transform.filter.id.exclude array in both the AOT
(angular-vite-plugin.ts) and fast-compile (fast-compile-plugin.ts) plugins, so the Angular
transform never runs for them and Vite's built-in raw handling stands:

exclude: [/node_modules/, 'type=script', '@ng/component', /[?&]raw\b/],

/[?&]raw\b/ matches foo.ts?raw and foo.ts?import&raw, but not plain foo.ts nor legitimate
query ids the handler must still compile (HMR foo.ts?t=123, foo.ts?component). The fix is
content-agnostic, so it covers both Angular and non-Angular .ts files.

// now works as with stock Vite
import source from './my-component.ts?raw';
console.log(source); // the file contents as a string

Test plan

  • nx format:check
  • pnpm test (vite-plugin-angular — new exclusion specs in angular-vite-plugin.spec.ts and
    fast-compile-plugin.spec.ts assert ?raw ids are excluded while plain/HMR ids still compile)
  • Manual verification

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

The plugin already routed .html?raw through a virtual id, but that mechanism exists solely to
satisfy Vite's server.fs Denied-ID security check — .html never reaches the Angular transform.
The .ts?raw problem is purely the transform filter shadowing Vite's raw output, so the narrow
filter-exclusion fix is the right tool and leaves the .html?raw path untouched.


Generated by Claude Code

The Angular transform filter matched query-stringed ids like `foo.ts?raw`
via TS_EXT_REGEX and recompiled them as TypeScript, discarding the
`export default "<source>"` that Vite's native raw loader produced. This
broke `import src from './file.ts?raw'` with "default is not exported".

Exclude `?raw` ids from the transform filter in both the AOT and fast
-compile plugins so Vite's built-in raw handling stands. Covers all
.ts/.cts/.mts files, Angular or not.

Closes #2356

https://claude.ai/code/session_01D4SdPZwfD2LtzqmZLQwdmw
@netlify

netlify Bot commented Jun 1, 2026

Copy link
Copy Markdown

Deploy Preview for analog-docs ready!

Name Link
🔨 Latest commit fcdd4ff
🔍 Latest deploy log https://app.netlify.com/projects/analog-docs/deploys/6a1e088a95dd480008c2a5fe
😎 Deploy Preview https://deploy-preview-2359--analog-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (2)
  • ^beta$
  • ^alpha$

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 41fcf000-9a78-44b8-8c5f-d2d16a00e83d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the scope:vite-plugin-angular Changes in @analogjs/vite-plugin-angular label Jun 1, 2026
@brandonroberts brandonroberts changed the base branch from main to beta June 2, 2026 02:17
@brandonroberts brandonroberts merged commit 722eccb into beta Jun 2, 2026
14 checks passed
@brandonroberts brandonroberts deleted the claude/issue-2356-tXyRK branch June 2, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:vite-plugin-angular Changes in @analogjs/vite-plugin-angular

Projects

None yet

Development

Successfully merging this pull request may close these issues.

?raw imports are shadowed by the Angular Vite plugin (docs / enhancement)

2 participants