Skip to content
Latchkey

OpenTelemetry JS "Cannot find module '@opentelemetry/...'" in CI

Node could not resolve an @opentelemetry/* package at require/import time. The instrumentation code imports it, but the package is not in the installed node_modules - usually a devDependency-only install or a peer that was never added.

What this error means

A test or app boot fails with "Error: Cannot find module '@opentelemetry/api'" or "@opentelemetry/auto-instrumentations-node", even though it runs on a developer machine where it was installed ad hoc.

node
Error: Cannot find module '@opentelemetry/api'
Require stack:
- /home/runner/work/app/app/src/tracing.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:...)

Common causes

The OTel package is not in package.json

@opentelemetry/api is a peer dependency of many instrumentation packages. If it was only present transitively before, a clean CI install may not hoist it, so the direct import fails.

Instrumentation packages installed only locally

The tracing setup was added and tested with an untracked local install; CI runs npm ci from the lockfile, which does not include it.

How to fix it

Add the OTel packages as real dependencies

  1. List every @opentelemetry/* package the code imports directly.
  2. Install them so they are recorded in package.json and the lockfile.
  3. Commit the updated lockfile so npm ci installs them in CI.
Terminal
npm install @opentelemetry/api @opentelemetry/sdk-node \
  @opentelemetry/auto-instrumentations-node

Match the API version required by instrumentations

The @opentelemetry/api version must satisfy the peer range of your SDK. Pin a compatible version if the install warns about an unmet peer.

Terminal
npm ls @opentelemetry/api

How to prevent it

  • Declare @opentelemetry/api explicitly; do not rely on transitive resolution.
  • Run npm ci locally to reproduce the exact CI install.
  • Commit the lockfile whenever you add instrumentation packages.

Frequently asked questions

What causes ""Cannot find module '@opentelemetry/...'""?
@opentelemetry/api is a peer dependency of many instrumentation packages. If it was only present transitively before, a clean CI install may not hoist it, so the direct import fails.
How do I fix "Cannot find module '@opentelemetry/...'"?
Add the OTel packages as real dependencies

Related guides

References

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