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

Next.js 14项目集成Firebase 10.x时出现'Firebase API key is not defined'错误求助

Next.js 14项目集成Firebase 10.x时出现'Firebase API key is not defined'错误求助

各位好!我正在给我的Next.js 14项目集成Firebase 10.x版本,结果在初始化Firebase的时候碰到了一个棘手的错误,实在搞不定来求助大家!

错误提示如下:

Firebase API key is not defined. Ensure NEXT_PUBLIC_FIREBASE_API_KEY is set in your environment variables. If using Firebase Studio, please enable billing for your Google Cloud project and retry.

这个错误是在我的firebase.ts文件里触发的,对应的代码片段是这样的:

if (!firebaseConfig.apiKey) {
  const errorMessage = "Firebase API key is not defined. Ensure NEXT_PUBLIC_FIREBASE_API_KEY is set in your environment variables. If using Firebase Studio, please enable billing for your Google Cloud project and retry.";
  throw new Error(errorMessage);
}

我已经在项目根目录的.env.local文件里配置了带NEXT_PUBLIC_前缀的Firebase API Key,也重启过开发服务器了,但还是会触发这个判断逻辑。有没有大佬能帮我排查下可能的问题?比如是不是环境变量的加载机制在Next.js 14里有变化?或者Firebase 10.x的初始化配置有什么需要注意的点?

备注:内容来源于stack exchange,提问作者Akhlaq Ahmad

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.13 16:19:41