fix(builders): preserve JSON import attributes in bundled output - #3160
Open
Mohith26 wants to merge 2 commits into
Open
fix(builders): preserve JSON import attributes in bundled output#3160Mohith26 wants to merge 2 commits into
Mohith26 wants to merge 2 commits into
Conversation
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.
🦋 Changeset detectedLatest commit: ecdd6c4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
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 |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3157, reported by @tmatkinson.
Import attributes (
with { type: 'json' }) were stripped at two points in the build pipeline: the SWC transform drops them unlessjsc.experimental.keepImportAttributesis set, and esbuild treats them as unsupported syntax for thees2022target 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 withERR_IMPORT_ATTRIBUTE_MISSING, breaking local step execution.Fix: enable
keepImportAttributesin the SWC transform and markimport-attributesas 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.