Bun Module Identifier
is-bun-module is a TypeScript utility library designed to programmatically identify and list modules within the Bun runtime environment. It distinguishes between Bun's native core modules (e.g., `bun:test`) and Node.js built-in modules that Bun has implemented (e.g., `fs`, `path`). The library provides functions to check individual module specifiers as well as retrieve comprehensive lists of all supported modules, optionally filtered by a specific Bun version string (e.g., '1.0.0' or 'latest'). As of version 2.0.0, the package is actively maintained with regular updates to reflect changes in Bun's module landscape, and it ships with full TypeScript type definitions for robust development.
Common errors
-
TypeError: isSupportedNodeModule is not a function
cause Attempting to use the old function name `isSupportedNodeModule` after upgrading to v2.0.0 or higher.fixRename `isSupportedNodeModule` to `isBunImplementedNodeModule`. -
ReferenceError: require is not defined
cause This package is distributed as an ES Module (ESM). Using CommonJS `require()` syntax in an ESM context (e.g., a `.js` file with `"type": "module"` or a `.mjs` file) will fail.fixUse ES module import syntax: `import { functionName } from 'is-bun-module';`. -
TypeError: Module 'is-bun-module' has no exported member 'Version'
cause Attempting to import the `Version` type after upgrading to v2.0.0 or higher.fixUpdate the type import from `import type { Version }` to `import type { BunVersion }`.
Warnings
- breaking The function `isSupportedNodeModule` was renamed to `isBunImplementedNodeModule`.
- breaking The TypeScript type `Version` was renamed to `BunVersion` to avoid naming conflicts and improve clarity.
- gotcha This library explicitly supports Bun v1.0.0 and newer. Using it with older Bun versions or expecting support for modules not yet implemented in v1.0.0+ may lead to unexpected results.
- gotcha The `bunVersion` parameter accepts semantic version strings (e.g., '1.0.0', '1.0.13') or the literal string 'latest'. Providing an invalid format will result in unpredictable behavior.
Install
-
npm install is-bun-module -
yarn add is-bun-module -
pnpm add is-bun-module
Imports
- isBunModule
const isBunModule = require('is-bun-module').isBunModule;import { isBunModule } from 'is-bun-module'; - isBunImplementedNodeModule
import { isSupportedNodeModule } from 'is-bun-module';import { isBunImplementedNodeModule } from 'is-bun-module'; - getBunBuiltinModules
const getBunBuiltinModules = require('is-bun-module').getBunBuiltinModules;import { getBunBuiltinModules } from 'is-bun-module'; - BunVersion
import type { Version } from 'is-bun-module';import type { BunVersion } from 'is-bun-module';
Quickstart
import {
isBunModule,
isBunImplementedNodeModule,
getBunBuiltinModules,
BunVersion
} from 'is-bun-module';
// Check specific Bun modules
console.log('Is "bun" a Bun module?', isBunModule('bun'));
console.log('Is "bun:test" a Bun module (Bun v1.0.0)?', isBunModule('bun:test', '1.0.0' as BunVersion));
console.log('Is "notBunModule" a Bun module?', isBunModule('notBunModule'));
// Check Node.js modules implemented in Bun
console.log('Is "fs" a Bun-implemented Node module?', isBunImplementedNodeModule('fs'));
console.log('Is "node:http2" a Bun-implemented Node module (Bun v1.0.0)?', isBunImplementedNodeModule('node:http2', '1.0.0' as BunVersion));
// Get a list of all builtin modules for the latest Bun version
const latestBuiltins = getBunBuiltinModules('latest');
console.log('First 5 builtin modules (latest Bun):', latestBuiltins.slice(0, 5));
// Example with an older Bun version
const bunV1_0_0Builtins = getBunBuiltinModules('1.0.0' as BunVersion);
console.log('Number of builtin modules in Bun v1.0.0:', bunV1_0_0Builtins.length);
// Type assertion for clarity when passing string literals as BunVersion
const currentBunVersion: BunVersion = '1.0.13';
console.log(`Checking 'crypto' against Bun ${currentBunVersion}:`, isBunImplementedNodeModule('crypto', currentBunVersion));