{"record":{"id":"f3ee447b6e9f2c2b","repo":"oven-sh/bun","slug":"builtin-bundler-could-not-resolve-specifier","errorCode":null,"errorMessage":"Builtin Bundler: Could not resolve \"${specifier}\" in \"${from}\". ${suffix}","messagePattern":"Builtin Bundler: Could not resolve \"(.+?)\" in \"(.+?)\"\\. (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/codegen/internal-module-registry-scanner.ts","lineNumber":85,"sourceCode":"    if (directMatch) return codegenRequireId(`${directMatch}/*${specifier}*/`);\n\n    const relativeMatch =\n      resolveSyncOrNull(specifier, path.join(basedir, path.dirname(from))) ?? resolveSyncOrNull(specifier, basedir);\n\n    const suffix =\n      'Only files in \"src/js\" besides \"src/js/builtins\" can be imported here. Note that the \"node:\" or \"bun:\" prefix is required here.';\n\n    if (relativeMatch) {\n      const found = moduleList.indexOf(path.relative(basedir, relativeMatch).replaceAll(\"\\\\\", \"/\"));\n      if (found === -1) {\n        throw new Error(\n          `Builtin Bundler: \"${specifier}\" cannot be imported from \"${from}\" because it doesn't get a module ID. ${suffix}`,\n        );\n      }\n      return codegenRequireId(`${found}/*${path.relative(basedir, relativeMatch)}*/`);\n    }\n\n    throw new Error(`Builtin Bundler: Could not resolve \"${specifier}\" in \"${from}\". ${suffix}`);\n  };\n\n  return {\n    requireTransformer,\n    nativeModuleIds,\n    nativeModuleEnums,\n    nativeModuleEnumToId,\n    internalRegistry,\n    moduleList,\n    nativeStartIndex,\n  } as const;\n}\n","sourceCodeStart":67,"sourceCodeEnd":98,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/internal-module-registry-scanner.ts#L67-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"Renaming or deleting a src/js file without updating importers; writing `import { ... } from \"fs\"` instead of \"node:fs\" in builtin code.","solutions":["Fix the specifier: check the file exists and the relative path is correct.","Add the required prefix for native modules: node:fs, node:path, bun:ffi, etc.","If the target is a new builtin, place it under one of the scanned src/js directories so it gets an ID."],"exampleFix":"// before\nimport { join } from \"path\";\n\n// after\nimport { join } from \"node:path\";","handlingStrategy":"validation","validationCode":"import { resolveSyncOrNull } from \"./helpers\";\nfor (const [specifier, from] of builtinImports) {\n  if (registry.has(specifier)) continue;\n  const ok = resolveSyncOrNull(specifier, path.join(basedir, path.dirname(from))) ?? resolveSyncOrNull(specifier, basedir);\n  if (!ok) throw new Error(`builtin ${from}: unresolvable import ${specifier}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write builtin imports with explicit extensions and node:/bun: prefixes.","Run a quick Bun.resolveSync dry-run over builtin imports in CI to catch typos before the full build."],"tags":["codegen","builtin-bundler","module-resolution","imports"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}