Postmortem·
Postmortem: Cloudflare Worker Missing Dependency on Deploy
How to fix missing dependencies when deploying Cloudflare Workers from within a monorepo workspace.
1. The Issue
- Symptom: The Cloudflare CI/CD pipeline failed to build a worker service with a missing dependency error:
✘ [ERROR] Could not resolve "@cloudflare/containers". - Impact: We were unable to deploy updates to the staging or production environments for the worker.
2. Root Cause
- Monorepo / Package Manager Quirks: The issue stemmed from an unintended interaction between Cloudflare's auto-detected build steps and
pnpmworkspaces. - Cloudflare's build system auto-detected
pnpmfrom our lockfiles and automatically ranpnpm install --frozen-lockfile. - Because the worker directory (
apps/core/workers/service/) is inside our project but isn't explicitly configured as a workspace member,pnpmtraversed upwards until it found thepnpm-workspace.yamlin the core directory. pnpmthen executed the install for the core application, placing dependencies inapps/core/node_modules/.- Since
@cloudflare/containerswas only listed in the worker's localpackage.json, it was entirely skipped by this workspace-levelpnpm install. - When
npx wrangler deploysubsequently ran, Wrangler'sesbuildbundler couldn't find the dependency anywhere in the tree.
3. The Resolution
- Using npm for Isolation: The fix was to switch the deploy script in the worker's
package.jsonto explicitly usenpminstead of relying on the environment's defaultpnpmcommand:"scripts": { "deploy:staging": "npm install && npx wrangler deploy --env staging" } - Why this works:
npmignorespnpm-workspace.yamlandpnpm-lock.yaml. Whennpm installis explicitly invoked within the worker directory, it successfully parses the localpackage.json, creating a localnode_modulesfolder with the necessary dependencies. Wrangler then successfully resolves and bundles the code.
Comments
pfSense Quickstart
Previous
pfSense Quickstart
pfSense Quickstart - Dive into the details of pfsense quickstart with this quick guide.
INCIDENT_REPORT
Postmortem: Serverless HTTP Driver Transaction Failures
Next
Postmortem: Serverless HTTP Driver Transaction Failures
Why database transactions fail in serverless HTTP drivers and how to architect around them using compensating transactions.
