Pulumi Error: 'could not find any node_modules folder' — Cause, Fix, and Troubleshooting Guide
Fix Pulumi 'could not find any node_modules folder' — dependencies not installed. Run npm/yarn/pnpm install before pulumi up. Causes and fixes.
- #pulumi
- #iac
- #troubleshooting
- #errors
Fixing errors like this? Get 500 free DevOps AI prompts
500 copy-paste AI prompts for the stack you actually run — one PDF, free.
Overview
error: could not find any node_modules folder means Pulumi’s Node.js language host started your TypeScript/JavaScript program but there is no node_modules directory where your dependencies (including @pulumi/pulumi) should live. Without node_modules, the host can’t require/import the Pulumi SDK or your providers, so it stops before running your program.
Almost always this is because a package manager install step never ran — you cloned the project, or you’re in CI, and nobody executed npm install / yarn / pnpm install. Occasionally it’s a path issue: Pulumi is looking in the wrong directory because of main: in Pulumi.yaml, a monorepo layout, or running pulumi from outside the project.
error: could not find any node_modules folder
Run 'npm install' (or the equivalent for your package manager) first.
Symptoms
pulumi up,pulumi preview, orpulumi installfails immediately withcould not find any node_modules folder.- The project directory has a
package.jsonbut nonode_modules/directory. - It reproduces on a fresh clone or a fresh CI checkout every time.
- In a monorepo, it happens because the program lives in a subfolder without its own installed deps.
Common Root Causes
1. Dependencies were never installed
The most common cause: package.json exists, but no install has been run in this checkout, so there is no node_modules.
$ ls
Pulumi.yaml index.ts package.json tsconfig.json
# no node_modules/ here
2. Running Pulumi from the wrong directory
If your working directory isn’t the project root (or you passed a --cwd/-C that points elsewhere), Pulumi looks for node_modules in a folder that doesn’t have it.
# Running from /repo while the program is in /repo/infra
pulumi -C infra up # infra/node_modules must exist, not /repo/node_modules
3. A main: path in Pulumi.yaml points to a subfolder
Pulumi.yaml’s main: sets where the program lives. If it points to a subdirectory, that directory (or its nearest ancestor) needs the installed node_modules.
name: my-infra
runtime: nodejs
main: ./src # deps must resolve from ./src
4. CI cache/artifact didn’t restore node_modules
In CI, a cache miss or a build stage that didn’t run install leaves the deploy stage without node_modules.
5. A pnpm/workspace layout Pulumi can’t traverse
pnpm’s symlinked store and monorepo workspaces sometimes place deps at the workspace root; Pulumi resolves upward, but a misconfigured workspace can leave the program folder without a reachable node_modules.
How to Diagnose
Confirm where you are, what’s declared, and whether deps exist.
# Are you in the project root? Is there a package.json but no node_modules?
pwd
ls -la
test -d node_modules && echo "node_modules present" || echo "MISSING node_modules"
# What does Pulumi think the program dir + runtime are?
cat Pulumi.yaml # check runtime: nodejs and any main: path
# Which package manager does the project use? (lockfiles tell you)
ls package-lock.json yarn.lock pnpm-lock.yaml 2>/dev/null
# In a monorepo, check whether the program subfolder has its own deps.
cat Pulumi.yaml | grep -i main
ls ./src/node_modules 2>/dev/null || echo "no node_modules in main dir"
Fixes
The direct fix — install dependencies: Run the install for your package manager in the project (or program) directory, then re-run Pulumi.
# npm
npm install
# yarn
yarn install
# pnpm
pnpm install
pulumi up
Let Pulumi install for you: pulumi install reads the project’s runtime and runs the appropriate package-manager install. You can also pin the package manager in Pulumi.yaml.
pulumi install
name: my-infra
runtime:
name: nodejs
options:
packagemanager: pnpm # npm | yarn | pnpm (auto-detected if omitted)
Install in the right directory (monorepo / main path): If main: points to a subfolder, install there — or install at the root the program resolves up to.
# If Pulumi.yaml has `main: ./src`
cd src && npm install && cd ..
pulumi up
Fix CI to install before deploy: Ensure the install step runs on every pipeline (or that the cache restore is required, not best-effort).
# Reproducible CI install from the lockfile, then deploy.
npm ci # or: yarn install --frozen-lockfile / pnpm install --frozen-lockfile
pulumi up --yes
Run Pulumi from the project root: Avoid stray -C/--cwd; cd into the directory that actually contains package.json and its installed node_modules.
What to Watch Out For
.gitignorealmost always excludesnode_modules— a fresh clone will never have it until you install.- Match the install command to the lockfile in the repo; mixing npm/yarn/pnpm can corrupt
node_modules. - In CI prefer
npm ci/ frozen-lockfile installs for reproducible builds. - If you set
packagemanagerinPulumi.yaml, make sure that tool is on PATH in every environment. - Deleting a stale
node_modulesand a mismatched lockfile, then reinstalling, resolves “half-installed” states that also trigger missing-module errors.
Related Guides
- Pulumi Error: ‘failed to load language plugin nodejs’ — Troubleshooting Guide
- Pulumi Error: ‘Running program failed with an unhandled exception’ — Troubleshooting Guide
- Pulumi Error: ‘could not load plugin’ — Troubleshooting Guide
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.