Skip to content
Latchkey

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.

Terminal
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

  1. Add the package to package.json and run bun install.
  2. Import a subpath the package actually exports.
  3. Check the package exports field for allowed entry points.
Terminal
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.

src/index.ts
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.

Frequently asked questions

What causes ""Cannot find package ... imported from""?
The dependency is missing from node_modules in CI because install did not run or the package is not in package.json.
How do I fix "Cannot find package ... imported from"?
Install and import a valid entry point

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card