Skip to content
Latchkey

Pulumi Node "Cannot find module" in CI

The Node.js Pulumi program tried to require a module that is not in node_modules. In CI this almost always means npm install (or the equivalent) did not run before pulumi up.

What this error means

A Pulumi step fails with "Error: Cannot find module '@pulumi/aws'" or a similar package, wrapped by "Running program ... failed".

pulumi
error: Running program '/home/runner/work/app/app' failed with an unhandled exception:
    Error: Cannot find module '@pulumi/aws'
    Require stack:
    - /home/runner/work/app/app/index.js

Common causes

Dependencies not installed before Pulumi

The job ran pulumi up without a prior npm ci / npm install, so node_modules is empty or incomplete.

Install ran in a different directory

Dependencies were installed in one directory but the Pulumi program lives in another, so the module is not on its require path.

How to fix it

Install dependencies before pulumi up

  1. Add an install step in the Pulumi program directory.
  2. Use npm ci for a reproducible install from the lockfile.
  3. Then run the Pulumi command.
Terminal
npm ci
pulumi up --yes

Point the Pulumi action at the program directory

Set work-dir so install and Pulumi run in the same place.

.github/workflows/ci.yml
- uses: pulumi/actions@v6
  with:
    command: up
    stack-name: dev
    work-dir: ./infra

How to prevent it

  • Run npm ci in the Pulumi program directory before every Pulumi command.
  • Cache node_modules or the npm cache keyed on the lockfile.
  • Keep install and Pulumi steps in the same working directory.

Frequently asked questions

What causes ""Cannot find module""?
The job ran pulumi up without a prior npm ci / npm install, so node_modules is empty or incomplete.
How do I fix "Cannot find module"?
Install dependencies before pulumi up

Related guides

References

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