Cloud Functions: Function failed on loading user code Google Cloud / Firebase Origin: Platform & cloud Last updated 4 Nov 2026

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

The function started but could not import/initialise your code, so every invocation fails.

Exact message you may see Function failed on loading user code. This is likely due to a bug in the user codeProvided module can't be loadedFunction failed on loading user codeCloud Functions Error: could not handle the requestError: function terminated. Recommended action: inspect logs for termination reason
Seen on: Google Cloud Node.js

Meaning

Open the logs for the real exception: a missing dependency in package.json/requirements.txt, a syntax error, wrong entry point name (--entry-point), or main/index mismatches. Test locally with the Functions Framework before deploying.

Common causes

  • Dependency missing from package.json/requirements.txt
  • Entry point name wrong
  • Syntax or import error at startup
  • Wrong runtime version
  • Top-level code failing (missing env var)

⚡ Quick fix

  1. Read Cloud Logging for the stack trace
  2. Run locally: npx @google-cloud/functions-framework --target=myFn
  3. Check --entry-point and main in package.json

Detailed fix by platform

gcloud

  1. gcloud functions logs read FUNCTION --region REGION --limit 50

How to diagnose

  1. Logs — Real exception?
  2. Entry — Name matches?
  3. Deps — Declared?

🔧 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):

API has not been used in project before or it is disabled — Google Cloud: 403 SERVICE_DISABLED — Cloud Resource Manager API has not been used in project 123456 before or it is disabled. Enable it by visiting (Google Cloud / Firebase)API has not been used…Artifact Registry: Permission artifactregistry.repositories.uploadArtifacts denied — Docker push: denied: Permission "artifactregistry.repositories.uploadArtifacts" denied on resource "projects/p/locations/l/repositories/r" (Google Cloud / Firebase)Artifact Registry: Pe…BigQuery: Access Denied: Project: User does not have bigquery.jobs.create permission — BigQuery: Access Denied: Project my-project: User does not have bigquery.jobs.create permission in project my-project (Google Cloud / Firebase)BigQuery: Access Deni…Cloud 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…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 (Google Cloud / Firebase)Container failed to s…Your active project does not match the quota project in your local ADC — gcloud/ADC: WARNING: Your active project does not match the quota project in your local Application Default Credentials file (Google Cloud / Firebase)Your active project d…Cloud Fun…

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.