You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase 0.9迁移至1.0部署报错:functions.config()不可用

Fixing "functions.config() is not available" Error in Firebase Functions Deployment

Hey there, let's work through this issue together. The error you're seeing is mostly tied to outdated Firebase CLI tooling, and we'll also make sure your config approach aligns with the latest best practices.

Step 1: Update Your Firebase CLI (Critical!)

The error message explicitly mentions using the latest Firebase CLI, which is likely the root cause here—you updated your function dependencies but not the CLI itself. Run this command to get the latest version:

npm install -g firebase-tools@latest

Verify the update worked by checking the version:

firebase --version

You should see a version number of 10.x or higher (as of 2024).

Step 2: Replace Deprecated functions.config() with Modern Config Methods

Since functions.config() is deprecated, here are the two recommended approaches to access your configuration:

This is the standard approach for modern Firebase Functions:

  1. Local Development: Create a .env file in your functions directory with your config values:
    MY_APP_API_KEY=your_actual_api_key
    MY_APP_DB_URL=your_database_url
    
    Make sure to add .env to your .gitignore to avoid committing sensitive data.
  2. In Code: Access these values using process.env:
    const apiKey = process.env.MY_APP_API_KEY;
    const dbUrl = process.env.MY_APP_DB_URL;
    
  3. Deployment: Set these environment variables in the Google Cloud Console (under your function's "Runtime, build, connections and security settings" > "Environment variables") or use the CLI command:
    firebase functions:config:set myapp.api_key="your_actual_api_key" myapp.db_url="your_database_url"
    
    Note: Config set via firebase functions:config:set will automatically be mapped to process.env in newer CLI versions.

Option 2: Use Runtime Config (For Firebase Functions v2+)

If you're using the v2 functions SDK (which you should be with the latest dependencies), you can define runtime config directly in your function definition:

import { onRequest } from "firebase-functions/v2/https";

export const myFunction = onRequest({
  runtimeConfig: {
    apiKey: process.env.MY_APP_API_KEY,
    dbUrl: process.env.MY_APP_DB_URL
  }
}, (req, res) => {
  // Access config via the request object
  const apiKey = req.runtimeConfig.apiKey;
  // Your function logic here
  res.send("Success!");
});

Step 3: Verify Dependencies & Deploy

Double-check that your package.json has the latest versions of firebase-functions and firebase-admin (you already updated these, but just to confirm):

{
  "dependencies": {
    "firebase-admin": "^12.0.0",
    "firebase-functions": "^4.0.0"
  }
}

Then deploy your functions again:

firebase deploy --only functions

That should resolve the functions.config() is not available error and get your updated app running smoothly.

内容的提问来源于stack exchange,提问作者Hector

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:31:46