Skip to content
Latchkey

Cannot find module from sibling workspace (build order) in CI

A package imported a sibling workspace package whose build had not run yet, so the compiled entry point does not exist. The dependency graph was not respected by the build order.

What this error means

A build or test fails with "Cannot find module @acme/ui" or "Cannot find module \".../dist/index.js\"" even though the package exists in the workspace.

pnpm
Error: Cannot find module '@acme/ui'
Require stack:
- /workspace/apps/web/src/main.ts
# @acme/ui/dist was never built

Common causes

Dependency not built first

The consumer ran before the sibling package produced its dist output, so the entry point is missing.

Build does not respect topology

A flat or parallel build script ignores the inter-package dependency graph.

Wrong main/exports path

The package points at a dist file that the build never emits.

How to fix it

Build in topological order

  1. Use a tool that respects the dependency graph so dependencies build first.
Terminal
# turbo respects dependsOn ^build
turbo run build
# or pnpm topological order
pnpm -r --workspace-concurrency=1 build

Declare build dependencies

  1. Add dependsOn ["^build"] (Turbo) or correct dependency edges so order is enforced.

How to prevent it

  • Drive builds through a topology-aware runner (Turbo/Nx dependsOn) so dependency packages always build before their consumers.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →