denoland/deno · error · Error

Unknown built-in module

Error message

Unknown built-in module

What it means

Deno's require shim throws this when a node: specifier is backed by neither a polyfill nor a native module - loadNativeModule returns nothing. It is Deno's stand-in for Node's ERR_UNKNOWN_BUILTIN_MODULE (the code comment marks the precise error as a TODO), so it surfaces as a plain Error without a code property, carrying only the stack trace pointing at the requiring package.

Solutions

  1. Upgrade Deno - builtin coverage expands every release
  2. Use the stack trace to identify the requiring package, then pin, patch, or replace that dependency
  3. Provide a shim: map the specifier to a local polyfill via an import map or deno.json imports

Example fix

// before
const inspector = require('node:internal-inspect'); // not polyfilled -> Error

// after: shim via deno.json imports
// deno.json: { 'imports': { 'node:internal-inspect': './shims/noop.ts' } }
// shim: export default {}; export const activate = () => {};
Defensive patterns

Strategy: fallback

Validate before calling

const KNOWN_UNSUPPORTED = new Set(['node:internal-inspect', 'node:trace_events']);
function requireBuiltin(id: string): unknown {
  if (KNOWN_UNSUPPORTED.has(id)) return require('./shims/noop.js');
  return require(id);
}

Type guard

function isNodeBuiltin(id: string): boolean {
  return id === 'node:' + id.slice(5) && require('node:module').isBuiltin(id);
}

Try / catch

try {
  nativeMod = require('node:the-builtin');
} catch (e) {
  if (e instanceof Error && e.message === 'Unknown built-in module') {
    nativeMod = require('./shims/the-builtin-shim.js'); // fallback implementation
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: require('node:<builtin-deno-has-not-polyfilled>') directly, or an npm dependency reaching for a builtin Deno does not implement; a builtin that exists only in newer Node versions than the Deno runtime tracks.

Common situations: Instrumentation, tracing, or metrics packages probing obscure builtins; dependencies written against a newer Node API surface; optional-builtins probing code that assumes every specifier resolves.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/be58eb55b1ae84f2. Report an issue: GitHub.

Appendix: source

Thrown at ext/node/polyfills/01_require.js:1557

      if (result.format === "builtin") {
        const module = loadNativeModule(id, id);
        if (module) {
          return module.exports;
        }
        const mod = new Module(builtinFilename, parent);
        mod.exports = {};
        mod.loaded = true;
        Module._cache[builtinFilename] = mod;
        return mod.exports;
      }
    }

    maybeEmitNativeModuleDeprecation(id);
    const module = loadNativeModule(id, id);
    if (!module) {
      // TODO:
      // throw new ERR_UNKNOWN_BUILTIN_MODULE(filename);
      throw new Error("Unknown built-in module");
    }

    return module.exports;
  }

  if (cachedModule !== undefined) {
    updateChildren(parent, cachedModule, true);
    if (!cachedModule.loaded) {
      return getExportsForCircularRequire(cachedModule);
    }
    return cachedModule.exports;
  }

  // A resolve hook that redirected `require('zlib')` to a file path must
  // not silently fall back to the native module via the original request.
  if (!SetPrototypeHas(cjsHookResolvedFilenames, filename)) {
    maybeEmitNativeModuleDeprecation(filename);
    const mod = loadNativeModule(filename, request);

View on GitHub (pinned to 9ad36f7a2c)