Skip to content

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

Open
crutchcorn wants to merge 2 commits intowithastro:mainfrom
crutchcorn:preact-babel
Open

fix: add ability to pass Babel props to Preact adapter#15862
crutchcorn wants to merge 2 commits intowithastro:mainfrom
crutchcorn:preact-babel

Conversation

@crutchcorn
Copy link
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

changeset-bot bot commented Mar 12, 2026

🦋 Changeset detected

Latest commit: 701da35

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
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.

1 participant