Cloud Functions: Error: Cannot find module 'X' (dependency missing at runtime)
The deployed function can't load a module that works locally.
Error: Cannot find module in Cloud FunctionsProvided module can't be loadedError: Cannot find module '../src/index' Meaning
The dependency is missing from package.json dependencies (devDependencies aren't installed in production builds), the lockfile and manifest are out of sync, or the entry point path is wrong. Check main in package.json and the build logs.
Common causes
- Package in devDependencies only
- package.json and lockfile out of sync
- Wrong
main/entry point - Monorepo dependency not bundled
- Native module build failure
⚡ Quick fix
- Move the package to
dependencies - Regenerate the lockfile and redeploy
- Verify
"main"points at the function file
Detailed fix by platform
Shell
npm install --save express && gcloud functions deploy fn --gen2 --runtime=nodejs20 --entry-point=handler
How to diagnose
- dependencies — Includes it?
- main — Correct?
- Lockfile — In sync?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- App Engine App Engine deploy failed: invalid app.yaml (runtime not supported / entrypoint / handlers)
- backend spec Firebase deploy: User code failed to load. Cannot determine backend specification
- Cloud Functions: Build failed Cloud Functions: Build failed: function.js does not exist / npm install failed with exit code 1 (Cloud Build step)
Most viewed in Google Cloud / Firebase
- Missing or insufficient permissions Firestore: FirebaseError: [code=permission-denied]: Missing or insufficient permissions
- Container failed to start Cloud Run: The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable
- 409: The resource already exists Compute Engine: ERROR: (gcloud.compute.instances.create) Could not fetch resource: The resource 'projects/p/zones/z/instances/vm-1' already exists
Other ways to find it
Where this error sits
Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 18 Nov 2026