Skip to content

fix(builders): preserve JSON import attributes in bundled output - #3160

Open
Mohith26 wants to merge 2 commits into
vercel:mainfrom
Mohith26:fix/builders-json-import-attributes
Open

fix(builders): preserve JSON import attributes in bundled output#3160
Mohith26 wants to merge 2 commits into
vercel:mainfrom
Mohith26:fix/builders-json-import-attributes

Conversation

@Mohith26

Copy link
Copy Markdown

Fixes #3157, reported by @tmatkinson.

Import attributes (with { type: 'json' }) were stripped at two points in the build pipeline: the SWC transform drops them unless jsc.experimental.keepImportAttributes is set, and esbuild treats them as unsupported syntax for the es2022 target and removes them. Inlined JSON imports were fine, but any JSON import that ends up externalized (relative project paths, bare specifiers, or dependency-internal imports like builtin-modules' ./builtin-modules.json) lost its attribute and crashed Node 22's ESM loader with ERR_IMPORT_ATTRIBUTE_MISSING, breaking local step execution.

Fix: enable keepImportAttributes in the SWC transform and mark import-attributes as supported syntax for every esbuild pass whose output Node loads directly. Includes a changeset (patch for @workflow/builders).

Regression tests cover both stripping points. 232 builders tests pass locally; the new tests fail without the fix.

Mohith26 added 2 commits July 28, 2026 13:25
Import attributes (`import data from './x.json' with { type: 'json' }`)
were silently stripped at two points in the build pipeline:

1. The SWC transform applied to every bundled JS/TS file drops import
   attributes unless `jsc.experimental.keepImportAttributes` is set.
2. esbuild considers import attributes unsupported syntax for the
   `es2022` target and removes them from emitted output.

Bundled JSON imports are inlined by esbuild so they were unaffected, but
any JSON import that ends up externalized in the output (relative
project-local paths, bare package specifiers, or dependency-internal
imports like builtin-modules' `./builtin-modules.json`) lost its
attribute and crashed at runtime on Node's ESM loader with
ERR_IMPORT_ATTRIBUTE_MISSING, breaking all local step execution.

Fix by enabling `keepImportAttributes` in the SWC transform and marking
`import-attributes` as supported syntax for every esbuild pass whose
output is loaded directly by Node.

Fixes vercel#3157
Covers both strip points from vercel#3157:

- applySwcTransform must emit `with { type: 'json' }` unchanged.
- A steps bundle with an externalized project-local JSON import and a
  dependency-shaped package using a JSON import attribute (mirroring
  builtin-modules) must keep the attribute in the generated output and
  load successfully under Node's native ESM loader.
@Mohith26
Mohith26 requested review from a team and ijjk as code owners July 28, 2026 18:42
@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ecdd6c4

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

This PR includes changesets to release 16 packages
Name Type
@workflow/builders Patch
@workflow/astro Patch
@workflow/cli Patch
@workflow/nest Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/nuxt Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite Patch
@workflow/vitest Patch
workflow Patch
@workflow/world-testing Patch
@workflow/core Patch
@workflow/web-shared Patch
@workflow/web Patch

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

@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

@Mohith26 is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@workflow/builders 4.1.3: JSON import attribute stripped from bundled deps, breaking all local step execution on Node 22

1 participant