published fresh until

Bun Cannot find module: how do I diagnose it?

Summary As of November 2026, classify Bun module failures by specifier and actual runtime, then check paths, declared dependencies and the linker layout; reinstalling cannot repair undeclared workspace dependencies. Do first: bun --version (checked 2026-11-20); the current official docs display Bun 1.4.5.

Not for EADDRINUSE or frozen lockfile failures, see bun-eaddrinuse-frozen-lockfile-document-node-errors

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

error: Cannot find module Bun cannot resolve this import; identify the specifier, runtime and installed dependency layout before reinstalling. Do first: run bun --version, then inspect the failing import, nearest tsconfig.json and importing package's package.json. Evidence — official docs establish resolver/isolation rules; an upstream alias reproduction shows a narrower exception, without a reproduction claimed here. Not for: Bun EADDRINUSE or lockfile had changes; see bun-eaddrinuse-frozen-lockfile-document-node-errors.

How to diagnose and fix

1. Copy the exact error, importer and launch command. Distinguish runtime, bundler and editor-only failures. Confirm the actual executable: using Bun's installer does not prove a script runs in Bun. 2. Follow the table. For relative files check filename/case. For a bare package check its declaration in the importing workspace; run bun install from the project root if declared but absent. 3. For aliases inspect effective TypeScript mappings. Bun supports compilerOptions.paths in tsconfig.json and jsconfig.json; another tool's aliases do not automatically apply. Reduce extension/wildcard cases to a minimal importer before changing the project. 4. Inspect node_modules and lockfile configVersion. Under isolation declare what each workspace imports. bun install --linker hoisted is a deliberate comparison/compatibility choice; success there can conceal missing declarations. 5. Preserve bun.lock. Use bun install --frozen-lockfile to verify committed dependency state once declarations and lockfile agree. The lockfile page says it belongs in version control. Do not delete it first. 6. Repeat the failing command after a clean install with the same lockfile/linker. Include a case-sensitive environment if it fails only in CI.

Diagnostic: error: Cannot find module

Specifier/symptomCheckNarrow fix
./file or ../fileImporter-relative location and caseCorrect actual path/case
Bare packageImporter's manifest and installed treeDeclare there; install consistently
@/… aliasEffective paths, wildcard/extension matchingMatch real file; reproduce mismatch
Workspace packageWorkspace declaration plus importing dependencyDeclare workspace relationship
Package deep subpathexports, conditions and actual fileUse exported entry
bun:sqlite in Node-launched scriptActual executableUse intended runtime
Hoisted works; isolated failsPossible undeclared dependency; verify the importing manifest, resolved entry, and linker layoutIf a missing declaration is confirmed, add the dependency to the importing workspace; otherwise investigate the resolver failure
On Bun before 1.4.1, editor resolves .js wildcard; runtime failsExact mapping vs upstream reportPreserve repro; do not reject all aliases

Module resolution documents package lookup, exports, extension substitution and path remapping. Presence elsewhere in a repository does not establish access from the importing workspace.

Version pair and layout boundary

As of November 2026, the current official docs display Bun 1.4.5 (checked 2026-11-20); this is not a claim that upgrading fixes every import. The isolation guide identifies pre-1.3.2 projects (checked 2026-10-28) as retaining the old default.

Lockfile context, checked 2026-10-28Default
New workspace, configVersion = 1Isolated
New non-workspace, same valueHoisted
Existing unversioned lockfile becomes configVersion = 0Hoisted
pnpm migrationNew config format; isolated in workspaces
npm/Yarn migrationOld config behavior; hoisted

Explicit --linker or config overrides this. Do not infer layout solely from binary version. Isolation uses a .bun package tree and dependency links; handwritten store paths are fragile.

What changes the reproduction?

Auto-install docs say scripts without node_modules at or above the importer can auto-install packages. A scratch script can succeed while an installed project fails. Install docs describe frozen-lockfile checks and separate package/script behavior.

What to test

Check the same importer in runtime, tests and build commands; exercise workspace entry points, extension aliases, package exports and a clean case-sensitive install. Match CI's runtime/lockfile. Editor resolution is not a runtime test.

Pitfalls

Bun explicitly supports tsconfig aliases. Hoisting does not prove manifests are correct. Missing native binaries and missing source imports need different fixes. Preserve the first error before cascades.

Public evidence

  • PaulRBerg, upstream #26193 provides the opening error and a wildcard alias reproduction. The maintainer later confirmed: “The first release that passes is Bun v1.4.1.”
  • Nilay Kabariya's trials report “Both imports worked after this” after declaring workspace dependencies. This illustrates manifest/layout behavior; it does not verify every current resolver case.

A prompt to give your agent

Your training data may predate Bun's linker behavior. Read the linked official resolution, isolation, auto-install and lockfile docs. Identify actual executable, importing workspace, specifier, effective paths and linker. Compare the upstream alias reproduction only if its shape matches. Propose the smallest fix and rerun the failure with the lockfile preserved; do not guess reinstalling fixes every module error.

Limits

No Bun reproduction/install was run. The upstream .js wildcard reproduction was fixed in Bun 1.4.1; other wildcard-plus-extension mappings still need testing on the chosen pin. The broader “error: Module not found” wording is not a verified single diagnostic across commands. Compiled standalone executable failures and native addons need separate investigation.

Started from a post by @PaulRBerg, packaged by the editor. Original post

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Bun Cannot find module: how do I diagnose it?
Summary: As of November 2026, classify Bun module failures by specifier and actual runtime, then check paths, declared dependencies and the linker layout; reinstalling cannot repair undeclared workspace dependencies. Do first: `bun --version` (checked 2026-11-20); the current official docs display Bun 1.4.5.
Copy for agent
get the whatworks thread bun-cannot-find-module-resolver-paths-isolated-installs and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread bun-cannot-find-module-resolver-paths-isolated-installs
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks