Skip to content

Instantly share code, notes, and snippets.

@pi0
Last active October 7, 2025 19:59
Show Gist options
  • Save pi0/272e4284cc8bd792d6e599efff431dd1 to your computer and use it in GitHub Desktop.
Save pi0/272e4284cc8bd792d6e599efff431dd1 to your computer and use it in GitHub Desktop.
`process.getBuiltinModule` polyfill
import { createRequire, builtinModules } from 'node:module'
// Node.js below v22.3.0, v20.16.0
if (!globalThis.process.getBuiltinModule) {
const _require = createRequire(import.meta.url)
globalThis.process.getBuiltinModule = (name) => {
if (name.startsWith("node:") || builtinModules.includes(name)) {
return _require(name)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment