Bun "Cannot find package X imported from" (ESM) in CI
An ESM import named a bare package Bun could not locate in node_modules, or the package does not export the subpath you imported. The message names both the package and the importing file.
What this error means
A step fails with "error: Cannot find package \"X\" imported from \"/path/Y\"", pointing at a bare specifier that is missing or a subpath the package does not expose.
error: Cannot find package "date-fns/format" imported from
"/home/runner/work/app/src/index.ts"Common causes
The package is not installed in this environment
The dependency is missing from node_modules in CI because install did not run or the package is not in package.json.
The subpath is not exported by the package
The package's exports map does not expose the subpath you imported, so Bun cannot resolve it even though the package exists.
How to fix it
Install and import a valid entry point
- Add the package to package.json and run
bun install. - Import a subpath the package actually exports.
- Check the package
exportsfield for allowed entry points.
bun install date-fns
# import a supported entry point
# import { format } from "date-fns";Fix a bad ESM subpath import
Use the entry point defined in the package exports map instead of a deep path that is not published.
import { format } from "date-fns";How to prevent it
- Declare every imported package in package.json and install it.
- Import only subpaths the package exports map exposes.
- Run bun install before build/test steps.