oven-sh/bun · error · Error

Builtin Bundler: Could not resolve "${specifier}" in "${from

Error message

Builtin Bundler: Could not resolve "${specifier}" in "${from}". ${suffix}

What it means

The builtin bundler's require transformer could not resolve the import at all: the specifier is not in the internal registry and Bun.resolveSync failed for both the importing file's directory and the src/js basedir. The message includes the specifier and the importing file, plus the rule that node:/bun: prefixes are required.

Source

Thrown at src/codegen/internal-module-registry-scanner.ts:85

    if (directMatch) return codegenRequireId(`${directMatch}/*${specifier}*/`);

    const relativeMatch =
      resolveSyncOrNull(specifier, path.join(basedir, path.dirname(from))) ?? resolveSyncOrNull(specifier, basedir);

    const suffix =
      'Only files in "src/js" besides "src/js/builtins" can be imported here. Note that the "node:" or "bun:" prefix is required here.';

    if (relativeMatch) {
      const found = moduleList.indexOf(path.relative(basedir, relativeMatch).replaceAll("\\", "/"));
      if (found === -1) {
        throw new Error(
          `Builtin Bundler: "${specifier}" cannot be imported from "${from}" because it doesn't get a module ID. ${suffix}`,
        );
      }
      return codegenRequireId(`${found}/*${path.relative(basedir, relativeMatch)}*/`);
    }

    throw new Error(`Builtin Bundler: Could not resolve "${specifier}" in "${from}". ${suffix}`);
  };

  return {
    requireTransformer,
    nativeModuleIds,
    nativeModuleEnums,
    nativeModuleEnumToId,
    internalRegistry,
    moduleList,
    nativeStartIndex,
  } as const;
}

View on GitHub (pinned to 8c5296ac45)

Solutions

  1. Fix the specifier: check the file exists and the relative path is correct.
  2. Add the required prefix for native modules: node:fs, node:path, bun:ffi, etc.
  3. If the target is a new builtin, place it under one of the scanned src/js directories so it gets an ID.

Example fix

// before
import { join } from "path";

// after
import { join } from "node:path";
Defensive patterns

Strategy: validation

Validate before calling

import { resolveSyncOrNull } from "./helpers";
for (const [specifier, from] of builtinImports) {
  if (registry.has(specifier)) continue;
  const ok = resolveSyncOrNull(specifier, path.join(basedir, path.dirname(from))) ?? resolveSyncOrNull(specifier, basedir);
  if (!ok) throw new Error(`builtin ${from}: unresolvable import ${specifier}`);
}

Prevention

When it happens

Trigger: A typo'd relative path, importing a file that does not exist under src/js, or using a bare specifier without the required node:/bun: prefix inside builtin modules.

Common situations: Renaming or deleting a src/js file without updating importers; writing `import { ... } from "fs"` instead of "node:fs" in builtin code.

Related errors


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/f3ee447b6e9f2c2b. Report an issue: GitHub.