module: MODULE_NOT_FOUND / ERR_MODULE_NOT_FOUND error shape, ResolveMessage extends Error (+1 test) - #34845
Closed
cirospaciari wants to merge 2 commits into
Closed
module: MODULE_NOT_FOUND / ERR_MODULE_NOT_FOUND error shape, ResolveMessage extends Error (+1 test)#34845cirospaciari wants to merge 2 commits into
cirospaciari wants to merge 2 commits into
Conversation
A failed require or import threw ResolveMessage with bun's own message and no code, so the ubiquitous userland pattern `err.code === 'MODULE_NOT_FOUND'` never matched. ResolveMessage now extends Error via a new prototypeBase class option in codegen -- the direction NodeUtilTypesModule.cpp's FIXME already sanctions -- and its message getter returns node's exact text for runtime import kinds: MODULE_NOT_FOUND with a Require stack and a requireStack array for CJS, ERR_MODULE_NOT_FOUND with the specifier truncated to the package name for bare ESM imports. The class itself is kept: Bun.build's log API documents name and constructor as ResolveMessage, and the getter is prefix-gated so invalid-URL, data-URL and ENAMETOOLONG texts are untouched, as is the CLI stderr display text. require.resolve now validates options.paths with node's exact ERR_INVALID_ARG_TYPE and ERR_INVALID_ARG_VALUE messages. Nine assertions across three bun-owned test files are updated to the node shapes; each is listed in the pull request for sign-off. Adds test-require-resolve-invalid-paths from Node v26.3.0, verbatim.
Collaborator
|
Updated 2:18 PM PT - Jul 20th, 2026
⏳ @autofix-ci[bot], your commit cf8ac6f is still building in
|
Contributor
|
Found 2 issues this PR may fix:
🤖 Generated with Claude Code |
Member
Author
|
Folded into #34660 (branch merged) as part of PR consolidation — same commits and tests, fewer PRs. |
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.
The ubiquitous userland pattern
err.code === 'MODULE_NOT_FOUND'never matched on bun: a failedrequire/importthrewResolveMessagewith bun's own message and nocodeat all. This is real compat value beyond any test — error-handling code across the npm ecosystem branches on these codes.Node's shapes (established on the v26.3.0 binary, not assumed)
require('./nope')MODULE_NOT_FOUNDCannot find module './nope'\nRequire stack:\n- <parent>+requireStack: [<parent>]import('nope/sub')ERR_MODULE_NOT_FOUNDCannot find package 'nope' imported from <parent>— specifier truncated to package name,@scope/namekeptrequire.resolve(x, {paths: [1]})ERR_INVALID_ARG_TYPEThe "paths" argument must be array of strings. Received an instance of ArrayBun now matches all three (verified byte-for-byte, including the truncation rules).
Approach: keep the class, make it node-shaped
ResolveMessageis documented public surface (Bun.buildlogs assertname/constructor), so replacing the thrown class would break bun's own API. Instead it now extends Error via a newprototypeBaseoption in the class codegen — the directionNodeUtilTypesModule.cpp's own FIXME sanctions ("delete this once ResolveMessage and BuildMessage extend Error"). The message getter returns node's exact text for runtime import kinds only, prefix-gated so invalid-URL/data-URL/ENAMETOOLONG texts and the CLI stderr display are untouched.Bun-owned assertion changes — 9, listed for sign-off
test/js/node/missing-module.test.js— 7 regexes updated fromCannot find package 'X' fromto node's CJS/ESM texts.test/js/bun/resolve/resolve-error.test.ts— 1:import(":://filesystem")now yieldsCannot find package '::', byte-identical to node.test/js/bun/resolve/import-meta.test.js— 1: relaxed a quoted-referrer assertion totoInclude(path)(node's Require-stack line is unquoted; intent — path-not-file-URL — preserved, passes on both binaries).Honest gaps left
name/constructorstay"ResolveMessage"(documented bun API); ESM message uses the given specifier without aurlprop;stackcarries no frames (bun doesn't capture JS frames at resolution time);--require missingkeeps bun's CLI error; pre-existing:require.resolve('nope', {paths})auto-installs instead of throwing.Of the 4 candidate tests, only
test-require-resolve-invalid-pathscan honestly convert (vendored, verbatim, 3 tampers detected, red on system bun). The others are product-blocked:test-require-mjsneeds--no-experimental-require-module(bun's require(esm) is always on),test-directory-importassertsERR_UNSUPPORTED_DIR_IMPORTwhile bun intentionally resolves directory imports.Regressions — interleaved before/after on saved binaries
resolve/ 296 tests 0 fail; node/module 89/0; worker_threads 91/0; misc 53/0; 48 vendored require/module files 48/0; bundler sample identical single pre-existing fail both sides; all cli-run deltas proven load-flakes by interleaving.
Bun.buildlogs unchanged except nowinstanceof Error.