Skip to content

Bun.plugin: run CommonJS contents from onLoad() and build.module() as CommonJS - #34112

Closed
robobun wants to merge 26 commits into
mainfrom
claude/farm/d47b951d/plugin-cjs-virtual-module
Closed

robobun wants to merge 26 commits into
mainfrom
claude/farm/d47b951d/plugin-cjs-virtual-module

Conversation

@robobun

@robobun robobun commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #19279
Part of #39786 (the CommonJS half)

Problem

  • A runtime Bun.plugin that returns CommonJS contents from onLoad or build.module() gives a silent empty module: the body never runs. bun test prints Ran 0 tests for such a file.
  • handleVirtualModuleResult (src/jsc/bindings/ModuleLoader.cpp:408) wraps every transpile result in an ES module provider and never reads isCommonJSModule.

Fix

  • The arm reads isCommonJSModule. require() evaluates its target and an import calls createCommonJSModule. Both use the source provider overloads.
  • fetchESMSourceCode forwards its Bun.ModuleGraph and a pending plugin promise keeps it, so the module goes into that graph's require.cache.
  • require() of a pending plugin promise still throws, and nothing loads the text later.
  • Verified: test/js/bun/plugin/plugins.test.ts, test/cli/test/coverage.test.ts (43 cases fail on main). Self-reviewed: 15 concerns raised, 14 addressed (Notes).

Background

  • The transpiler prints CommonJS as a wrapper function. JSCommonJSModule calls it. Nothing calls it in an ES module.
  • bun test --isolate caches each file's transpiled source by path (IsolatedModuleCache). Plugin text must stay out. The provider overloads never insert there.
  • Considered bun test: Vitest compatibility #44833's design (plugin contents through the file consumers): it changes functions that every load runs. This PR changes only the plugin arm.

Downsides

Notes

Repro

Bun.plugin({
  name: "v",
  setup(b) {
    b.module("virt-cjs", () => ({ contents: "globalThis.RAN = 1; module.exports = { a: 1 };", loader: "js" }));
  },
});
console.log({ ...(await import("virt-cjs")) }, require("virt-cjs"), globalThis.RAN);
// main:    {} {} undefined
// this PR: { a: 1, default: { a: 1 } } { a: 1 } 1

Text that the transpiler reads as CommonJS has the bug: module.exports, exports.x, a require() call, typeof module, a top-level this. The same text in a file on disk works. The tests compare each result with that file.

Measurements (release builds of the merge base 5c6d4e2 and of this PR, same machine, same flags)

  • no-plugin import: 72 -> 72 self instructions in fetchESMSourceCode<true>. no-plugin require(): 129 -> 129 in jsFunctionRequireCommonJS and 152 -> 152 in fetchCommonJSModule. import.meta.require() of an ES module: 108 -> 108 in fetchESMSourceCodeSync. (gdb single-step count of one call, calls stepped over)
  • JSCommonJSModule::evaluate and createCommonJSModule (both overloads of each), Zig::SourceProvider::create, IsolatedModuleCache::insert, jsFunctionRequireCommonJS, Bun__onFulfillAsyncModule: 0 bytes changed (nm -S and a disassembly diff). The ASSERT is not in a release build.
  • release .text: +2304 bytes (size -A). handleVirtualModuleResult<true> / <false>: +1294 / +907 bytes (nm -S).
  • plugin ES-text result (the case that worked before): 137 -> 136 self instructions in handleVirtualModuleResult<true>, 12 -> 13 conditional branches, +0 cells for each load (gdb single-step, heapStats()).
  • PendingVirtualModuleResult: 48 -> 64 bytes allocated for each pending plugin import (heap snapshot).
  • 200 failed require() of a pending build.module(): PendingVirtualModule cells 200 -> 0, promises +400 -> +200, unhandledRejection events for text that does not parse 200 -> 0.
  • plugin CommonJS, import then require: callback 1 / body 1. require then import: callback 2 / body 1. Isolation cache entries for plugin keys across 2 isolated test files: 0.
  • new host functions: 0. Codegen or type inputs changed: 0.

Behaviour changes

  • Files that a plugin served as CommonJS text now run. A test file that reported 0 tests runs its tests and can fail. A CommonJS preload listed after the plugin registers its hooks. The lines of such a file count for coverageThreshold. A throw at load time is no longer hidden behind {}. This includes files in a "type": "module" package that have no import or export and call require().
  • After require() of a promise-returning callback throws require() async module ... is unsupported, Bun no longer transpiles the text when the promise settles. Before, text with a syntax error gave a late unhandledRejection. A promise that rejects still gives one unhandledRejection.
  • CommonJS text from a plugin is refused under --disallow-code-generation-from-strings=strict, as ES text from a plugin is.

Not fixed here

Relation to #44833

#44833 replaces this arm. It sends plugin contents to fetchCommonJSModuleNonBuiltin and fetchESMSourceCode, which also fixes the value loaders. It is pinned to a preview build of WebKit and conflicts with main today, so this PR is the interim fix. This PR uses the same early return for a pending promise and the same ModuleGraph field on PendingVirtualModuleResult.

When #44833 merges main after this PR:

  1. Take the side of bun test: Vitest compatibility #44833 in the 5 conflict regions of ModuleLoader.cpp and the 1 of ModuleLoader.h.
  2. Delete the two parameters graph and specifierJS at the end of handleVirtualModuleResult. They merge in without a conflict and nothing reads them there.
  3. Keep the ASSERT in ZigSourceProvider.cpp. The tests merge without a conflict. bun test: Vitest compatibility #44833 has a describe that compares with a file in the same way, so the rows that both have can go.

The decision on which PR lands first belongs to the author of #44833. If #44833 lands first, this PR closes and its tests move there.

Tests

  • bun bd test test/js/bun/plugin/plugins.test.ts test/cli/test/coverage.test.ts: 198 pass. With the source of main: 43 fail. Release builds gave the same counts at 197 and 42, before the case for a fulfilled promise was added.
  • Each part of the fix has a case that fails without it. Forcing the ResolvedSource overloads fails both --isolate cases: the isNewEntry assertion in a debug build, and the next test file gets the plugin's text for the file on disk. No early return for a pending promise leaves a module in require.cache. A null graph at either call site, or no graph in the pending cell, fails a Bun.ModuleGraph case. Never taking the ResolvedSource overloads fails the Module.wrapper case. ignoreESModuleAnnotation as false fails the import rows in a package of type module.
  • BUN_JSC_validateExceptionChecks=1 on the plugin file: all pass.
  • Debug build, no assertion failure: test/js/bun/plugin/, test/js/bun/test/mock/mock-module*.test.ts, test/cli/test/isolation.test.ts, test/cli/test/coverage.test.ts, test/cli/run/{preload-test,run-cjs,commonjs-invalid,commonjs-no-export,esm-defineProperty,require-and-import-trailing}, test/js/node/module/{node-module-module,require-extensions,module-sourcemap}, test/bundler/{bundler_compile,bundler_compile_prelinked,bun-build-compile}, test/js/node/disallow-code-generation-from-strings.test.ts, and the CommonJS, plugin and require cases of test/js/bun/module-graph/.
  • test/cli/run/require-cache.test.ts has one case that times out on a release build of main and of this PR alike (don't leak file paths > via import()).

Self-review

15 concerns raised, 14 addressed: 5 new test groups (a package of type module, the fetch without a promise, a Bun.ModuleGraph under bun test, code coverage, a result with no loader), more table rows, a corrected comment, and the text of this body. Not done:

  • A test for a warm transpiler cache. I checked it by hand: text over 4 KiB from a plugin gives the same exports on a cold and on a warm BUN_RUNTIME_TRANSPILER_CACHE_PATH.
  • Two suggested source changes were measured and dropped. The parameters in the position that bun test: Vitest compatibility #44833 uses changed the code for a no-plugin require() (152 -> 153 instructions in fetchCommonJSModule). A lookup that skips the dropped provider added 3328 bytes of .text.

History


no test proof · iteration 11 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/js/bun/plugin/plugins.test.ts

@robobun

robobun commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 4:14 AM PT - Oct 24th, 2026

✅ @robobun, your commit 450309b15979432a9bd75bbfd1e7bcbcad8d741e passed in Build #131808! 🎉


🧪   To try this PR locally:

bunx bun-pr 34112

That installs a local version of the PR into your bun-34112 executable, so you can run:

bun-34112 --bun

@github-actions

Copy link
Copy Markdown
Contributor

Found 3 issues this PR may fix:

  1. CJS file exports disappear after being processed by a plugin with onLoad #21369 - CJS file exports disappear after being processed by a plugin with onLoad — exact symptom of the missing isCommonJSModule branch
  2. Bun plugins load hook issue with CJS require #22683 - Plugin load hook with CJS require causes silent failure — onLoad returning contents with require() never evaluates the module body
  3. Trying to import react native by striping flow types using a runtime plugin #10083 - React Native CJS modules return empty Module {} when imported through a runtime plugin stripping Flow types

If this is helpful, copy the block below into the PR description to auto-close these issues on merge.

Fixes #21369
Fixes #22683
Fixes #10083

🤖 Generated with Claude Code

@robobun

robobun commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

Verified all three against this change (the file-namespace onLoad shape each of them uses now has a dedicated test in 9bc93d5). Added the Fixes lines to the description.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 95ec6c9 and ff5143f.

Files selected for processing: 1
  • test/js/bun/plugin/plugins.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

Plugin-provided CommonJS source is evaluated or created as a CommonJS module. Pending virtual-module results retain module-graph context. Tests cover exports, async behavior, caching, isolation, wrapper overrides, and coverage.

Changes

CommonJS virtual modules

Layer / File(s) Summary
CommonJS result handling
src/jsc/bindings/ModuleLoader.cpp, src/jsc/bindings/ModuleLoader.h, src/jsc/bindings/ZigSourceProvider.cpp
The result handler evaluates a supplied CommonJS module or creates one when needed. Pending results retain the module graph, which the async callback passes back with the original specifier. A source-provider assertion checks that CommonJS status matches sourceType == Program.
CommonJS exports and plugin interoperability
test/js/bun/plugin/module-plugins.ts, test/js/bun/plugin/plugins.test.ts
Plugin fixtures and tests cover module.exports, exports.*, onLoad, import and require behavior, export mapping, side effects, errors, and pass-through loading.
Async resolution, runtime state, and coverage
test/js/bun/plugin/module-plugins.ts, test/js/bun/plugin/plugins.test.ts, test/cli/test/coverage.test.ts
Tests cover execution and retry behavior, module-graph state, cache behavior, wrapper overrides, isolation, strict code-generation restrictions, and coverage for a plugin-loaded CommonJS module.

Suggested reviewers: jarred-sumner

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Minimal · up to ff514

No actionable merge-blocking issue is identified; the change is mergeable after normal checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title is concise, specific, and accurately summarizes the main change: CommonJS contents returned by Bun plugins now execute as CommonJS.
Linked Issues check Passed Directly linked issue #19279 requires that a plugin onLoad result with loader 'js' and CommonJS contents (module.exports.foo = "foo";) provides named imports to the importer, including under bun test.…
Out of Scope Changes check Passed All changed areas connect to the CommonJS plugin result path required by #19279. (1) The isCommonJSModule arm in handleVirtualModuleResult is the core fix. (2) The hasOverriddenModuleWrapper branch se…
Description check Passed The description provides a detailed explanation of the problem, fix, scope, limitations, and verification results. It does not use the template headings exactly, but it includes the required informati…
Full details: Linked Issues check

Explanation

Directly linked issue #19279 requires that a plugin onLoad result with loader 'js' and CommonJS contents (module.exports.foo = "foo";) provides named imports to the importer, including under bun test. The whole-PR diff of src/jsc/bindings/ModuleLoader.cpp adds an arm in handleVirtualModuleResult that checks res->result.value.isCommonJSModule. When no CommonJS module exists yet, the arm calls Bun::createCommonJSModule with a source provider built from the plugin text, so module.exports keys become named exports. When a CommonJS module exists (require path), the arm calls commonJSModule->evaluate. The PR description reports test/js/bun/plugin/plugins.test.ts and test/cli/test/coverage.test.ts as 197 passing on this PR and 42 failing on main. The PR description also states that the plugin test file could not run on the author's machine and defers to CI. Residual uncertainty: this assessment did not read every new test body. The conclusion relies on the implementation hunk, the PR description, and the test names in the summary.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to the CommonJS plugin result path required by #19279. (1) The isCommonJSModule arm in handleVirtualModuleResult is the core fix. (2) The hasOverriddenModuleWrapper branch selects the wrapper-aware evaluation path inside that same arm. It does not alter file-on-disk handling. (3) The early return for a pending promise, guarded by commonJSModule and !wasModuleMock, changes only require() of a pending plugin promise. The PR description states that this still throws. (4) The ModuleGraph field in PendingVirtualModuleResult and its forwarding through fetchESMSourceCode and jsFunctionOnLoadObjectResultResolve supports the require.cache placement of the same plugin CommonJS modules. (5) The debug-only ASSERT in ZigSourceProvider.cpp checks the CommonJS flag against the Program source type for the new arm. (6) Test and fixture changes in plugins.test.ts, module-plugins.ts, and coverage.test.ts exercise this path. The PR description discloses the resulting behavior changes, including files that previously reported 0 tests now running. No change was found that is unrelated to plugin CommonJS handling. Residual uncertainty: the full test file bodies were not read in this review.

Full details: Description check

Explanation

The description provides a detailed explanation of the problem, fix, scope, limitations, and verification results. It does not use the template headings exactly, but it includes the required information under equivalent sections such as Problem, Fix, and Tests.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. fix(runtime): preserve named exports of plugin-loaded CommonJS modules #31770 - Also fixes CJS virtual modules in Bun.plugin by modifying the same handleVirtualModuleResult function in ModuleLoader.cpp to check isCommonJSModule and route through the CJS evaluator

🤖 Generated with Claude Code

robobun and others added 2 commits July 14, 2026 03:27
…uator

A runtime Bun.plugin onLoad/module() callback returning contents that the
transpiler detects as CommonJS (module.exports, exports.x, bare require())
produced a silent empty module: the body never evaluated, side effects never
ran, import() succeeded with zero exports, and require() returned {}.

handleVirtualModuleResult's OnLoadResultTypeCode arm called
Bun__transpileVirtualModule and then unconditionally wrapped the result in an
ESM Zig::SourceProvider, never checking res->result.value.isCommonJSModule.
The transpiler had printed the source as a CJS wrapper function that nothing
ever invoked. Every other consumer of a transpile result (Bun__onFulfillAsyncModule,
fetchESMSourceCode, fetchCommonJSModuleNonBuiltin) already branches on
isCommonJSModule; this one did not.

Route the CJS case through commonJSModule->evaluate() (require path) or
Bun::createCommonJSModule() (import path), matching the on-disk code path.

Co-authored-by: isaacs <i@izs.me>
@robobun
robobun force-pushed the claude/farm/d47b951d/plugin-cjs-virtual-module branch from 9bc93d5 to a8bb4a4 Compare July 14, 2026 03:28
@robobun

robobun commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

Re: duplicate detection. #31770 (@isaacs, June 3) does make the same source change. It currently has merge conflicts against main and covers a subset of the entry points; this PR is rebased with broader coverage (builder.module() sync/async, exports.x, error propagation, custom-namespace onLoad). Added Co-authored-by: isaacs <i@izs.me> to the source commit (fe79fc6) and referenced #31770 in the description. Happy to close this in favor of #31770 if preferred.

Comment thread src/jsc/bindings/ModuleLoader.cpp Resolved
runVirtualModule runs before the IsolatedModuleCache lookup in both
fetchCommonJSModule and fetchESMSourceCode, so routing virtual CJS through
evaluate()/createCommonJSModule() inserted without a prior lookup. Under
bun test --isolate, loading the same virtual CJS specifier from two files
tripped ASSERT_WITH_MESSAGE(result.isNewEntry) in debug. Plugin output is
not the on-disk file at the cache key anyway, so pass isBuiltIn=true to
suppress the insert.
Comment thread test/js/bun/plugin/plugins.test.ts Resolved
Comment thread src/jsc/bindings/ModuleLoader.cpp Resolved
… isBuiltIn

isBuiltIn=true also skips code coverage, changes SourceOrigin to builtin://,
and on the require() path with an overridden Module.wrap skips the original
source_code deref before the pointer is overwritten at :1383. Thread a
dedicated skipIsolationCache bool that gates only the IsolatedModuleCache
insert so plugin-sourced CJS keeps isBuiltIn=false for SourceProvider::create.
@robobun

robobun commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI on 2d80dbf (build 93749, rebased onto current main with the .cts/.mts pass-through tests from #31770 folded in): the diff itself is green. test/js/bun/plugin/plugins.test.ts passes on every lane and the gate confirms fail-before/pass-after on both ASAN and release. All automated review threads are resolved; the final automated pass found no bugs and deferred to a maintainer for sign-off on the skipIsolationCache/wasRequire plumbing.

Remaining CI failures on 93749 are 9 lanes all tagged [flaky] (child_process IPC, fs read-stream, sourcetextmodule-leak, in-process-cron, webview, grpc deadlines, napi make_callback, dlopen, cluster-shared-leak), each passed alone or on retry. None touch ModuleLoader, JSCommonJSModule, or the plugin path. This is the 8th build of this branch with only rotating unrelated flakes.

Ready for a maintainer to merge (or to close in favor of #31770).

Comment thread test/js/bun/plugin/plugins.test.ts Resolved
Comment thread src/jsc/bindings/ModuleLoader.cpp Resolved
…ed async plugin result

require() of an async virtual module throws 'async module unsupported' and
removes its requireMap entry, but the then-reaction wired onto the plugin's
promise still fires later. For CJS contents that reaction now reaches
createCommonJSModule, which would re-insert a fresh unevaluated entry into
require.cache.

Record wasRequire on PendingVirtualModuleResult and have the resolve handler
bail when the specifier is no longer in requireMap (i.e. the originating
require() already threw and cleaned up). The already-fulfilled-promise require
path is unaffected since its requireMap entry is still present when the
reaction runs.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/jsc/bindings/ModuleLoader.cpp`:
- Around line 395-416: Update the async virtual-CJS completion path around
createCommonJSModule to pass false, true so it also skips the isolation cache,
matching the synchronous branch shown here. Add isolate regression coverage for
both async module() and import() virtual-CJS flows.

In `@test/js/bun/plugin/plugins.test.ts`:
- Around line 332-342: Replace the timing-based Bun.sleep(5) wait in the async
CommonJS module test with a fixture-controlled settlement promise that resolves
when the plugin’s continuation has completed. Await that signal before the
second require.cache assertion, preserving the existing side-effect and error
expectations without relying on timing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d0d82829-45db-4c26-adfa-a9f03a7bb187

📥 Commits

Reviewing files that changed from the base of the PR and between ede88a0 and f35deb1.

📒 Files selected for processing (6)
  • src/jsc/bindings/JSCommonJSModule.cpp
  • src/jsc/bindings/JSCommonJSModule.h
  • src/jsc/bindings/ModuleLoader.cpp
  • src/jsc/bindings/ModuleLoader.h
  • test/js/bun/plugin/module-plugins.ts
  • test/js/bun/plugin/plugins.test.ts

Comment thread src/jsc/bindings/ModuleLoader.cpp Resolved
Comment thread test/js/bun/plugin/plugins.test.ts Resolved
Comment thread test/js/bun/plugin/plugins.test.ts Resolved
Comment thread src/jsc/bindings/ModuleLoader.cpp Resolved
Comment thread src/jsc/bindings/ModuleLoader.cpp Resolved
robobun and others added 7 commits October 23, 2026 15:26
…he CommonJS evaluator

The merge of main left the earlier fix uncompilable. createCommonJSModule
takes a JSModuleGraph since #42590. This reworks the fix on main.

handleVirtualModuleResult reads isCommonJSModule after it transpiles a
plugin's contents. The arm builds the Program provider and calls the
overloads of JSCommonJSModule::evaluate and createCommonJSModule that take a
provider. Those overloads never insert into the IsolatedModuleCache, so the
skipIsolationCache parameter is removed. With an overridden Module.wrapper
the arm calls the ResolvedSource overloads. They apply the override and do
not cache in that state.

fetchESMSourceCode forwards its graph and key. PendingVirtualModuleResult
carries the graph in a 4th internal field. An import from a Bun.ModuleGraph
puts the module in the require cache of that graph.

require() of a pending plugin promise returns before a pending cell exists.
fetchCommonJSModule throws as before, and nothing loads the text later. The
wasRequire flag is removed.

Zig::SourceProvider::create asserts that a CommonJS source is a Program and
that no other source is.

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
… file

The subprocess cases move into a describe block of their own. New cases:

- A table of CommonJS texts. Each is loaded by import(), require(),
  import.meta.require() and an import statement, from a sync and a pending
  callback, and compared with the same text on disk.
- The body runs once for import then require, and for require then import.
- A body that throws on require() runs again on the next require().
- A plugin-served entry point, and a plugin-served test file under bun test.
- A module of a Bun.ModuleGraph, from a sync and a pending callback.
- An overridden Module.wrapper.
- --disallow-code-generation-from-strings=strict.
- The repro of #39786.

Under --isolate, the next test file must get the file from disk, not the
plugin's text. The case for require() of a pending promise now also loads the
module by import() afterwards.
….wrapper override

An import under an override does not run the module body, for a file and for a plugin's text alike. The comment said that the override is applied.
- The table runs a second time in a package of type "module", where an
  import does not read the __esModule flag.
- New rows: a `// @Bun @bun-cjs` text, an empty .cjs file, jsx and tsx
  loaders, contents as bytes, and a result with no loader.
- require() of an ES module that imports the text (the fetch without a
  promise).
- A Bun.ModuleGraph in the test process itself, and a module that a required
  ES module imports in a graph.
- An import under an overridden Module.wrapper gives what a file gives.
- Code coverage: the text is covered when one test file imports it and the
  next requires it under --isolate.
Comment thread src/jsc/bindings/ModuleLoader.cpp Resolved
@robobun robobun changed the title Bun.plugin: route CommonJS virtual-module source through the CJS evaluator Bun.plugin: run CommonJS contents from onLoad() and build.module() as CommonJS Oct 24, 2026
@robobun

robobun commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status for 450309b:

  • Reproduced on 1.4.3, on a release build of main and on a debug build of main. import() of a build.module() that returns module.exports = { a: 1 } gives {}, require() gives {}, and the body does not run. With this branch both give the exports and the body runs once.
  • bun bd test test/js/bun/plugin/plugins.test.ts test/cli/test/coverage.test.ts: 198 pass. With the source of main: 43 fail.
  • bun test: Vitest compatibility #44833 replaces the same arm with a deeper change. The Notes in the description say how the two merge. Which one lands first is a maintainer decision.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings marked 🟡 are optional suggestions and need no follow-up push.

Comment thread src/jsc/bindings/ModuleLoader.cpp Resolved
Comment thread src/jsc/bindings/ModuleLoader.cpp Resolved
Comment thread test/js/bun/plugin/plugins.test.ts Resolved
Comment thread test/js/bun/plugin/plugins.test.ts Resolved
…ocess output

A build.module() callback that is async and awaits nothing returns a promise
that is already fulfilled. require() loads its CommonJS source at once.

The three `bun test` cases assert stdout, each (pass) or (fail) line, the
counts and the exit code in one object. The two .cts and .mts pass-through
cases use the run() and json() helpers of the block.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings marked 🟡 are optional suggestions and need no follow-up push.

Comment thread src/jsc/bindings/ModuleLoader.cpp Resolved
Comment thread test/js/bun/plugin/plugins.test.ts Resolved
Seven cases deleted their module from require.cache after the last
expect. A failed assertion skipped the delete, and the next case that
loads the same name got the cached module.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review completed

Nothing new to post: everything this review found is already covered by existing comments on this pull request or didn't merit a separate one.

@robobun

robobun commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as stale: this PR conflicts with main, and its last commit is from 2026-10-24.

The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR.

@robobun robobun closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot return CommonJS from loaders

2 participants