# Cloud Functions: Build failed: function.js does not exist / npm install failed with exit code 1 (Cloud Build step)

**Code:** `Cloud Functions: Build failed` · **Category:** Google Cloud / Firebase · **Seen on:** Google Cloud

The deployment's build step (Cloud Build) failed, so no new function version was created.

## Meaning

Open the build logs link from the error. Frequent causes: a failing `npm install`/`pip install`, missing `package.json`/`requirements.txt`, private dependencies, incompatible runtime version, or the Cloud Build/Artifact Registry API/permissions missing for 2nd gen functions.

## Common causes

- Dependency install failing (version, private repo)
- Missing main file or wrong runtime
- Cloud Build API disabled or SA lacks permissions
- Source directory wrong
- Artifact Registry permission missing

## Quick fix

1. Read the Cloud Build log for the failing step
2. Enable `cloudbuild.googleapis.com` and `artifactregistry.googleapis.com`
3. Pin supported runtime (`--runtime nodejs20`)

## Detailed fix by platform

### gcloud

1. `gcloud builds list --limit 3` then `gcloud builds log BUILD_ID`

## How to diagnose

1. **Step** — Which build step failed?
2. **APIs** — Enabled?
3. **Runtime** — Supported?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/gcp/cloud-functions-build-failed)
