Skip to content

Bun does not support module.registerHooks #27369

Open

Description

@kevgeoleo

What version of Bun is running?

1.3.10-canary.80+76754a8ea

What platform is your computer?

Linux 5.10.0-12-amd64 x86_64 x86_64

What steps can reproduce the bug?

Hi,

Bug can be reproduced using the following PoC:

import module from 'node:module'
console.log(module.registerHooks)

What is the expected behavior?

Node gives following op:

PS D:\secbench_test_windows\graphs> node .\a.mjs
[Function: registerHooks]

What do you see instead?

Bun shows:

PS D:\secbench_test_windows\graphs> bun run .\a.mjs
undefined

Additional information

Documentation shows Bun is compatible:
https://bun.com/reference/node/module
https://bun.com/reference/node/module/default/registerHooks

Activity

  1. github-actions commented on Feb 23, 2026

    @github-actions
    Contributor

    Found 3 possible duplicate issues:

    1. node:module.register does not exist. #11905
    2. node:module stripTypeScriptTypes is documented but is not actually supported #25058
    3. Error when importing findPackageJSON method from node:module #23898

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. exoRift commented on Jun 14, 2026

    @exoRift

    Was looking into this as a way to set imports when a package is installed during script runtime, as there's no way to recompute the module graph without restarting the script. Doesn't seem like it's supported, which is a bummer.

  3. robobun commented on Aug 13, 2026

    @robobun
    Collaborator

    A full implementation (hooks actually invoked for both require() and import) is in progress in #35690. The export-only stub in #34174 was closed in its favor. Leaving this open until #35690 merges.

  4. CaliLuke commented on Oct 29, 2026

    @CaliLuke

    Still reproducible with Bun 1.4.4 on macOS arm64:

    bun -e 'console.log(typeof require("node:module").registerHooks)'
    # undefined
    node -e 'console.log(typeof require("node:module").registerHooks)'
    # function (Node 26.12.1)

    A concrete impact is loading a bundled Vite+ 1.3.0 configuration that uses import.meta.resolve. With vite-plus@1.3.0 and msw@2.15.0 installed, this standalone configuration reproduces the failure:

    // vite.config.mjs
    console.log(import.meta.resolve('msw/mockServiceWorker.js'));
    export default { test: { include: ['smoke.test.ts'] } };
    // smoke.test.ts
    import { expect, it } from 'vite-plus/test';
    it('loads', () => { expect(1).toBe(1); });

    bun --bun vp test run --config vite.config.mjs fails before collecting tests:

    Cannot find module 'vite-module-runner:import-meta-resolve/v1/["msw/mockServiceWorker.js","file:///.../vite.config.mjs"]'
    

    The same configuration passes with node node_modules/.bin/vp test run --config vite.config.mjs. Using createRequire(import.meta.url).resolve('msw/mockServiceWorker.js') also works under Bun. Implementing the synchronous module hooks would allow the bundled configuration's virtual resolution imports to work without changing the resolver used by the configuration.

  5. CaliLuke commented on Nov 1, 2026

    @CaliLuke

    Retested with Bun 1.4.4 and Vite+ 1.4.0 using a small config that resolves msw/mockServiceWorker.js:

    console.log(import.meta.resolve("msw/mockServiceWorker.js"));
    export default { test: { include: ["smoke.test.ts"] } };

    Running bun --bun vp test run --config vite.config.mjs fails before test collection with a Cannot find module 'vite-module-runner:import-meta-resolve/...' error. Replacing the resolution with createRequire(import.meta.url).resolve("msw/mockServiceWorker.js") allows the same one-test configuration to pass. With Node 26.12.1, module.registerHooks is a function; under Bun 1.4.4 it is undefined.

    This reproduces the missing module-hook behavior on the current Bun runtime and a current Vite+ release.

  6. AdityaBorkar commented on Nov 4, 2026

    @AdityaBorkar

    +1 this remains a blocker for using cloudflare in vite using bun
    ref: cloudflare/cf#252 (comment)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions