Skip to content

Fix Vite 8 (Rolldown/OXC) transform error in CopyPageButton script - #408

Open
hongyi-chen wants to merge 1 commit into
mainfrom
fix/copypagebutton-vite8-oxc-ts-transform
Open

Fix Vite 8 (Rolldown/OXC) transform error in CopyPageButton script#408
hongyi-chen wants to merge 1 commit into
mainfrom
fix/copypagebutton-vite8-oxc-ts-transform

Conversation

@hongyi-chen

Copy link
Copy Markdown
Collaborator

Problem

Running the docs dev server fails for anyone on a fresh install with a Vite transform error:

[ERROR] [vite] Internal server error: Transform failed with 3 errors:
[PARSE_ERROR] Type assertion expressions can only be used in TypeScript files.
[ src/components/CopyPageButton.astro?astro&type=script&index=0&lang.ts ]
Plugin: vite:oxc

Root cause

Astro compiles client <script> blocks into virtual modules tagged ?astro&type=script&index=0&lang.ts and relies on the transformer to strip TypeScript. astro@7.1.3 now pulls in Vite 8 (Rolldown-powered, using the OXC transformer instead of esbuild — note Plugin: vite:oxc). OXC infers the language from the real .astro file extension rather than the lang.ts query suffix, so it parses the script as plain JS and rejects the TS-only syntax in CopyPageButton.astro.

This is why it hits "someone else" and not everyone: devs with older node_modules still have Vite 7 (esbuild), which handled lang.ts correctly. A clean install (npm ci) lands on Vite 8.1.5 + Rolldown/OXC and breaks.

Fix

CopyPageButton.astro is the only processed (bundled) <script> in the repo containing TS-only syntax — every other script is is:inline (untransformed) or already plain JS. Convert its three bits of TS syntax to JSDoc casts, which are valid JS that OXC accepts while preserving the type info for astro check:

  • as HTMLTemplateElement | null/** @type {HTMLTemplateElement | null} */ (...)
  • (e: MouseEvent)/** @param {MouseEvent} e */
  • e.target as Node/** @type {Node} */ (e.target)

Runtime behavior is unchanged.

Verification

On the exact reproducing stack (Vite 8.1.5 + Rolldown 1.1.5 + Astro 7.1.3):

  • npm run dev -- --force starts cleanly with no vite:oxc / [PARSE_ERROR].
  • npm run build completes with exit 0 (full OXC transform of all client scripts), no parse/transform errors.

Conversation: https://staging.warp.dev/conversation/d5fabfce-7be4-4574-b96b-0faa9a8ea1ec
Run: https://oz.staging.warp.dev/runs/019faacc-1953-76c9-8392-d925b72c068d

This PR was generated with Oz.

Astro compiles client `<script>` blocks into virtual modules tagged
`?astro&type=script&index=0&lang.ts` and relies on the transformer to
strip TypeScript. With Astro 7 now pulling in Vite 8 (Rolldown-powered,
using the OXC transformer instead of esbuild), OXC infers the language
from the real `.astro` extension rather than the `lang.ts` query, so it
parses the script as plain JS and rejects the TS-only syntax with
`[PARSE_ERROR] Type assertion expressions can only be used in
TypeScript files`.

Convert the three bits of TS-only syntax in the script block to JSDoc
casts (valid JS that OXC accepts) so the type info is preserved for
`astro check` while `npm run dev`/`build` succeed on Vite 8:
- `as HTMLTemplateElement | null` -> `/** @type {...} */ (...)`
- `(e: MouseEvent)` -> `/** @param {MouseEvent} e */`
- `e.target as Node` -> `/** @type {Node} */ (e.target)`

Verified with a clean `astro dev` startup and a full `astro build` (exit
0, no vite:oxc parse errors) on Vite 8.1.5 + Rolldown 1.1.5 + Astro 7.1.3.

Co-Authored-By: Oz <oz-agent@warp.dev>
@cla-bot cla-bot Bot added the cla-signed label Jul 28, 2026
@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Jul 28, 2026 10:27pm

Request Review

@hongyi-chen
hongyi-chen marked this pull request as ready for review July 28, 2026 22:31
@oz-for-oss

oz-for-oss Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

@hongyi-chen

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overview

This PR updates CopyPageButton.astro so the bundled client script avoids TypeScript-only syntax that Vite 8/OXC parses incorrectly from Astro virtual script modules. The replacement JSDoc casts preserve the intended DOM types while keeping the emitted script valid JavaScript.

Concerns

  • No blocking correctness, security, or spec-alignment concerns found in the annotated diff.

Verdict

Found: 0 critical, 0 important, 0 suggestions

Approve

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

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.

1 participant