/errors/bun/cannot-find-module
Bun: error: Cannot find module './utils' from '/path/to/index.ts'
- tool
- Bun
- exit code
- 1
- versions
- Bun 1.x
- os
- any
error: Cannot find module './utils' from '/path/to/index.ts' means Bun could not resolve an import. The first quoted part is the import exactly as written; the second is the file that contains it. For relative imports the path is resolved from that file's folder, so ./utils must exist next to it as utils.ts, utils.js, utils/index.ts or similar. For a package name, install it with bun add.
Reproduce it
echo 'import { greet } from "./missing"; greet();' > index.ts
npx --yes bun@1 run index.ts 2>&1 | head -1
exit "${PIPESTATUS[0]}"Output · exit 1
error: Cannot find module './missing' from '/tmp/work/index.ts'
Bun also prints its version and platform below the error.
Fix
echo 'export function greet() { console.log("hello"); }' > missing.ts
echo 'import { greet } from "./missing"; greet();' > index.ts
npx --yes bun@1 run index.tsOutput
hello
For a package, the same message names the package: Cannot find module 'zod' from '/app/src/index.ts'. Run bun add zod and run the file again.
| Import | Bun looks for |
|---|---|
| ./utils | utils.ts, utils.tsx, utils.js, utils.jsx, utils/index.* next to the importing file |
| ../lib/db | The same, one folder up |
| zod | node_modules/zod, in the current folder or a parent folder |
| @/components/Button | An alias from compilerOptions.paths in tsconfig.json |
Running a file that does not exist at all (bun run nofile.ts) gives a different message: error: Module not found "nofile.ts".