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".
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.jsCommon 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
- Add an install step in the Pulumi program directory.
- Use
npm cifor a reproducible install from the lockfile. - Then run the Pulumi command.
npm ci
pulumi up --yesPoint the Pulumi action at the program directory
Set work-dir so install and Pulumi run in the same place.
- uses: pulumi/actions@v6
with:
command: up
stack-name: dev
work-dir: ./infraHow to prevent it
- Run
npm ciin the Pulumi program directory before every Pulumi command. - Cache
node_modulesor the npm cache keyed on the lockfile. - Keep install and Pulumi steps in the same working directory.