Skip to content

/errors/bun/cannot-find-module

Bun: error: Cannot find module './utils' from '/path/to/index.ts'

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
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

bash
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

bash
echo 'export function greet() { console.log("hello"); }' > missing.ts
echo 'import { greet } from "./missing"; greet();' > index.ts
npx --yes bun@1 run index.ts

Output

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.

ImportBun looks for
./utilsutils.ts, utils.tsx, utils.js, utils.jsx, utils/index.* next to the importing file
../lib/dbThe same, one folder up
zodnode_modules/zod, in the current folder or a parent folder
@/components/ButtonAn 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".

Sources