Cloud Functions: Error: Cannot find module 'X' (dependency missing at runtime)

The deployed function can't load a module that works locally.

Exact message you may see Error: Cannot find module in Cloud FunctionsProvided module can't be loadedError: Cannot find module '../src/index'
Seen on: Google Cloud Node.js

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

  1. Move the package to dependencies
  2. Regenerate the lockfile and redeploy
  3. Verify "main" points at the function file

Detailed fix by platform

Shell

  1. npm install --save express && gcloud functions deploy fn --gen2 --runtime=nodejs20 --entry-point=handler

How to diagnose

  1. dependencies — Includes it?
  2. main — Correct?
  3. 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:

Where this error sits

Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):

App Engine — App Engine deploy failed: invalid app.yaml (runtime not supported / entrypoint / handlers) (Google Cloud / Firebase)App Enginebackend spec — Firebase deploy: User code failed to load. Cannot determine backend specification (Google Cloud / Firebase)backend specCloud Functions: Build failed — Cloud Functions: Build failed: function.js does not exist / npm install failed with exit code 1 (Cloud Build step) (Google Cloud / Firebase)Cloud Functions: Buil…Cloud Functions: Function execution took 60000 ms, finished with status: timeout — Cloud Functions: Function execution took 60002 ms, finished with status: 'timeout' (Google Cloud / Firebase)Cloud Functions: Func…Cloud Functions: Function failed on loading user code — Cloud Functions: Provided module can't be loaded / Function failed on loading user code. This is likely due to a bug in the user code (Google Cloud / Firebase)Cloud Functions: Func…DEP0040 — DeprecationWarning: The `punycode` module is deprecated (DEP0040) (Node.js)DEP0040EBADENGINE — npm WARN EBADENGINE Unsupported engine / The engine "node" is incompatible with this module (Node.js)EBADENGINEERR_PACKAGE_PATH_NOT_EXPORTED — Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './x' is not defined by "exports" (Node.js)ERR_PACKAGE_PATH_NOT_…Cannot fi…

Explore the map of this error Full error map →

🧠 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.