Skip to content

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

@adamchal

Description

@adamchal

Astro Info

Astro                    v6.1.3
Vite                     v7.3.1
Node                     v25.8.2
System                   macOS (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/cloudflare (v13.1.7)
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When a .ts file default-imports .astro components (the same pattern used by @storyblok/astro's virtual:import-storyblok-components), astro build logs errors like:

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

The astro-frontmatter-scan esbuild plugin (in @astrojs/cloudflare) registers its onLoad handler without a namespace filter:

// esbuild-plugin-astro-frontmatter.js
build.onLoad({ filter: /\.astro$/ }, async (args) => { ... });

This intercepts .astro files in both the file and html esbuild namespaces. When a .ts file imports a .astro file, esbuild resolves that .astro import in the html namespace. The plugin extracts only the frontmatter (which has no export default), so the default import fails.

The build ultimately succeeds because Vite falls back when dep scanning fails ("Skipping dependency pre-bundling"), but the errors are noisy and dep pre-bundling is skipped entirely, which may hurt performance.

What's the expected result?

No errors during dependency scanning. The astro-frontmatter-scan plugin should scope its onLoad to the file namespace, and provide a separate handler for the html namespace that appends export default {} — matching what Vite's own html-type loader would have done.


Potential fix

Add a namespace filter to the existing handler and add a second handler for the html namespace:

// Scope to "file" namespace (original behavior):
build.onLoad({ filter: /\.astro$/, namespace: "file" }, async (args) => ({
  contents: extractFrontmatter(args.path),
  loader: "ts",
}));

// "html" namespace: append a default export so default imports resolve:
build.onLoad({ filter: /\.astro$/, namespace: "html" }, async (args) => ({
  contents: extractFrontmatter(args.path) + "\nexport default {};",
  loader: "ts",
}));

Link to Minimal Reproducible Example

https://github.com/adamchal/cloudflare-frontmatter-scan

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugAn edge case that only affects very specific usage (priority)pkg: cloudflareRelated to the Cloudflare adapter

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions