Skip to content

fix(cloudflare): add namespace filter to astro-frontmatter-scan esbuild plugin#16272

Open
barry3406 wants to merge 5 commits intowithastro:mainfrom
barry3406:fix/esbuild-frontmatter-namespace-filter
Open

fix(cloudflare): add namespace filter to astro-frontmatter-scan esbuild plugin#16272
barry3406 wants to merge 5 commits intowithastro:mainfrom
barry3406:fix/esbuild-frontmatter-namespace-filter

Conversation

@barry3406
Copy link
Copy Markdown
Contributor

Fixes #16203

Problem

The astro-frontmatter-scan esbuild plugin registers its onLoad handler without a namespace filter. In esbuild, an unfiltered onLoad matches all namespaces, including html. When a .ts file default-imports an .astro component, Vite's dep scanner resolves the .astro file into the html namespace. The plugin intercepts it and returns only the extracted frontmatter — which has no export default — causing:

[ERROR] No matching export in "html:/path/to/Component.astro" for import "default"

Fix

Add namespace: 'file' to the onLoad call so the plugin only handles .astro files resolved from the filesystem. Files in the html namespace now fall through to Vite's built-in htmlTypeOnLoadCallback, which already appends export default {} for non-.vue files.

Test plan

  • Verified against the reproduction repo from the issue: error no longer occurs
  • file namespace behavior is unchanged — same handler, same logic, only the namespace scope is narrowed

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 9, 2026

🦋 Changeset detected

Latest commit: 80e3e01

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Apr 9, 2026
@barry3406
Copy link
Copy Markdown
Contributor Author

Hey @ematipico, could you take a peek at this when you get a chance? It's a small fix for a Cloudflare adapter regression where astro-frontmatter-scan was matching the html namespace by accident. Happy to adjust anything if needed.

@rururux
Copy link
Copy Markdown
Contributor

rururux commented Apr 10, 2026

Hi! Could you please add a changeset and some tests to verify the fix?
These will be needed for the PR to be merged. Thanks!

Adds a unit test for `astroFrontmatterScanPlugin` that asserts the
plugin only registers `onLoad` handlers scoped to the `file` namespace,
plus behavioural tests for frontmatter extraction, empty-frontmatter
fallback, and the top-level `return` -> `throw` rewrite. The first
case is a regression guard for the cross-namespace bug fixed in this PR.

Also adds a changeset for `@astrojs/cloudflare`.
@barry3406
Copy link
Copy Markdown
Contributor Author

barry3406 commented Apr 10, 2026

Hey @rururux — done! Pushed:

I verified the regression assertion fails when the namespace: "file" filter is removed and passes once it's back. Went with a unit test for speed, but if you'd rather see this as a full integration fixture instead, happy to swap it out. Thanks for the review!

'@astrojs/cloudflare': patch
---

Fixes a Cloudflare adapter regression where importing an `.astro` component as a default export from a `.ts` file failed with `No matching export in "html:..." for import "default"`. The internal `astro-frontmatter-scan` esbuild plugin now scopes its `onLoad` handler to the `file` namespace, so `.astro` files resolved into Vite's `html` namespace fall through to Vite's built-in handler instead of being intercepted by the frontmatter-only loader.
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.

Thanks for adding the changeset!
It looks a bit technical, so could you please make it more concise?
You can refer to this link for some guidance: https://contribute.docs.astro.build/docs-for-code-changes/changesets/

@barry3406
Copy link
Copy Markdown
Contributor Author

Done — shortened the changeset to one user-facing line per the docs guide. Thanks!

@barry3406 barry3406 force-pushed the fix/esbuild-frontmatter-namespace-filter branch from 7a5b50e to 1bc8d2d Compare April 10, 2026 10:11
@barry3406
Copy link
Copy Markdown
Contributor Author

Thanks @rururux — read the changesets guide properly this time and force-pushed a revised version that drops the implementation note and follows the lived Fixes X failing with Y when Z pattern from fix-svelte-prerender-node.md. Let me know if it's still off and I'll keep trimming.

@rururux
Copy link
Copy Markdown
Contributor

rururux commented Apr 10, 2026

Thanks! The changeset looks good now.
Regarding the tests, I personally think it might be better to add an integration test rather than a unit test, similar to the existing ones.
This is because the current test doesn't seem to verify if the No matching export in 'html:...' for import 'default' message is actually resolved by these changes.

@barry3406
Copy link
Copy Markdown
Contributor Author

Thanks @rururux — converted to an integration test in test/ts-astro-import.test.js. The fixture mirrors the structure from the issue reproduction repo: a lib/ui.ts that default-imports Inner.astro and Outer.astro (where Outer wraps Inner), consumed by a page. It runs through loadFixture and fixture.build(), modelled on top-level-return.test.js.

The test captures the Astro logger output and asserts that neither No matching export in "html:..." for import "default" nor Failed to run dependency scan appears during the build.

I verified the regression actually fires: with namespace: 'file' removed from the plugin, both assertions fail with the exact error from #16203. Dropped the old unit test in the same commit. Let me know if the fixture or assertions need adjusting!

@barry3406 barry3406 force-pushed the fix/esbuild-frontmatter-namespace-filter branch from 39ae94b to f32ce4f Compare April 10, 2026 13:59
Per review feedback. The unit test only asserted that the plugin
registers `namespace: 'file'`; it never verified that the
"No matching export in 'html:...' for import 'default'" error from
withastro#16203 actually disappears.

The new fixture mirrors the issue reproduction: a `lib/ui.ts` registry
default-imports `Inner.astro` and `Outer.astro` (Outer wraps Inner),
consumed by a page. The test runs a build through `loadFixture` and
captures the Astro logger output, asserting that neither the
"No matching export" line nor "Failed to run dependency scan" appears.
Removing `namespace: 'file'` makes both assertions fire with the exact
error message from withastro#16203.
@barry3406 barry3406 force-pushed the fix/esbuild-frontmatter-namespace-filter branch from f32ce4f to 80e3e01 Compare April 10, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: astro-frontmatter-scan esbuild plugin missing namespace filter causes "No matching export" errors during dep scan

2 participants