esm: report the importing file when a named import cannot be resolved - #36635
Draft
robobun wants to merge 2 commits into
Draft
esm: report the importing file when a named import cannot be resolved#36635robobun wants to merge 2 commits into
robobun wants to merge 2 commits into
Conversation
Fixes #5582. The SyntaxError thrown during module linking when a named import has no matching export only named the imported-from module; in a multi-file project there was no way to find which file contained the failing import statement. The fix lives in JavaScriptCore (oven-sh/WebKit#378): ImportEntry now records the specifier's source offset and initializeEnvironment attaches sourceURL / line / column to the SyntaxError. Bun's existing error printer reads those properties and renders the location (with sourcemap remapping and the source-line preview), so the bun-side change is just the WEBKIT_VERSION bump and the regression test. WEBKIT_VERSION points at the PR preview build for now; it will be updated to the merged main sha once oven-sh/WebKit#378 lands.
Collaborator
Author
|
Updated 3:14 AM PT - Aug 1st, 2026
❌ @robobun, your commit d5059e8 has 1 failures in
🧪 To try this PR locally: bunx bun-pr 36635That installs a local version of the PR into your bun-36635 --bun |
Contributor
|
Found 1 issue this PR may fix:
🤖 Generated with Claude Code |
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 #5582. Fixes #20667.
Reproduction
The error names
dep.tsbut notindex.ts, so in a project where many files import fromdep.tsthere is no way to locate the failingimportstatement. Node printsfile:///repro/index.ts:1with the offending line.Cause
The error is thrown in
CyclicModuleRecord::initializeEnvironmentduring module linking, from a C++ microtask with no JS on the stack. TheSyntaxErrorcarries only the message text and is handed to Bun's printer with an empty stack trace, sofromErrorInstance'ssourceURL/line/columnfallback finds nothing.Fix
JavaScriptCore change in oven-sh/WebKit#378:
ImportEntryrecords the specifier's source offset (oneunsigned), and the throw site attachessourceURL/line/column(both asErrorInstance::m_sourceURL/m_lineColumnand asDontEnumown properties) for the importing module. Bun's existingZigException.cpp::fromErrorInstancealready reads those properties andremap_zig_exceptionalready remaps them through the sourcemap, so no bun-side code change is needed.With the bump:
The indirect-export (
export { x } from "./dep") and ambiguous-binding cases route through the same helper and at least carry the importing module'ssourceURL.Verification
test/js/bun/resolve/esm-link-error-location.test.tscovers the direct case, an indirect chain (entry → middle → dep) that must namemiddle.mjsand not the entry point, and a caught dynamicimport()rejection whose.sourceURL/.linepoint at the importing file. All three fail on released bun and pass with the bump.test/js/bun/typescript/type-export.test.ts(import not found) andtest/js/bun/resolve/resolve-error.test.tsare unchanged and green.WebKit bump
WEBKIT_VERSIONcurrently points at the preview build of oven-sh/WebKit#378 so CI can exercise the change. It will be updated to the mergedmainsha before this is undrafted. The preview built green on every WebKit CI lane (linux glibc/musl/android, macOS, windows x64/arm64, freebsd).The gate's fail-before check cannot mechanically prove this because the fix is in the bumped prebuilt, not in
src/; stashingsrc/leaves the bump in place. The fail-before evidence isUSE_SYSTEM_BUN=1 bun test test/js/bun/resolve/esm-link-error-location.test.ts→ 3 fail.[decide:webkit] gate passed · iteration 1 · 2 files touched
passes on PR (with fix)
diff hotspot
gate history · 2 passed · 0 rejected · iteration 1
evidence per changed file