Skip to content

fix: add ability to pass Babel props to Preact adapter#15862

Merged
Princesseuh merged 5 commits into
withastro:mainfrom
crutchcorn:preact-babel
Mar 24, 2026
Merged

fix: add ability to pass Babel props to Preact adapter#15862
Princesseuh merged 5 commits into
withastro:mainfrom
crutchcorn:preact-babel

Conversation

@crutchcorn
Copy link
Copy Markdown
Contributor

Changes

This PR adds the ability to pass Babel options to the Preact adapter since the underlying Preact Vite plugin does not support Babel config files: https://github.com/preactjs/preset-vite/blob/main/src/index.ts#L132

Context

When adding Preact to our project, we found that adding an import attribute:

import * as languages from "../../content/data/languages.json" with { type: "json" };

Broke our project with the error:

You are using import attributes, without specifying the desired output syntax.
Please specify the "importAttributesKeyword" generator option, whose value can be one of:
 - "with"        : `import { a } from "b" with { type: "json" };`
 - "assert"      : `import { a } from "b" assert { type: "json" };`
 - "with-legacy" : `import { a } from "b" with type: "json";`

22:56:23 [ERROR] Expected "{" but found "type"

And the only way we could fix this was to add:

{ "generatorOpts": { "importAttributesKeyword": "with" } }

As the Babel options in the Preact plugin.

Testing

This was pulled into the Playful Programming project branch having this issue and validated the fix there.

Docs

No changes should be required to merge this, but happy to write new docs to explain how one can leverage this functionality.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 12, 2026

🦋 Changeset detected

Latest commit: 20c1817

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 pkg: preact Related to Preact (scope) pkg: integration Related to any renderer integration (scope) labels Mar 12, 2026
Copy link
Copy Markdown
Member

@Princesseuh Princesseuh left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!

@Princesseuh Princesseuh merged commit 06fba3a into withastro:main Mar 24, 2026
21 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Mar 24, 2026
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) pkg: preact Related to Preact (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants