Skip to content

Replacements for is-builtin-module

Node.js (since 16.x)

For determining if a module is built-in or not, you can use isBuiltin:

ts
import { isBuiltin } from 'node:module'
import isBuiltinModule from 'is-builtin-module'

isBuiltin('fs') // true
isBuiltinModule('fs') // true

Node.js 6.x to 15.x

Before Node.js 16.x, isBuiltin was not available, so you need to implement your own check using builtinModules:

ts
import { builtinModules } from 'node:module'
import isBuiltinModule from 'is-builtin-module'

function isBuiltin(moduleName) { 
  const name = moduleName.startsWith('node:') 
    ? moduleName.slice(5) 
    : moduleName 

  return builtinModules.includes(name) 
} 

isBuiltin('fs') // true
isBuiltinModule('fs') // true

Getting all built-in modules

For a full list of built-in modules (available since Node.js 6.x), you can use builtinModules:

ts
import { builtinModules } from 'node:module'

console.log(builtinModules)

Released under the MIT License. (a44cbf10)