Firebase Functions模拟器启动报错:无法确定后端规格 求排查
Firebase Functions模拟器启动失败:Cannot determine backend specification
启动Firebase Functions模拟器时,出现以下错误:
⬢ functions: Failed to load function definition from source: FirebaseError: User code failed to load. Cannot determine backend specification
此前该错误为间歇性出现,只能靠反复重启解决,如今已100%触发,完全阻塞开发。经过数小时排查仍无头绪。
环境信息
firebase-tools版本:
$ firebase --version 13.17.0
最小复现代码
functions/index.js
const admin = require("firebase-admin/app"); admin.initializeApp(); const functions = require("firebase-functions/v1"); exports.created = functions.auth.user().onCreate(async (user) => { const email = user.email; console.log(email); return; });
functions/package.json
{ "name": "functions", "description": "Cloud Functions for Firebase", "scripts": { "lint": "eslint .", "serve": "firebase emulators:start --only functions", "shell": "firebase functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log" }, "engines": { "node": "18" }, "main": "index.js", "private": true, "dependencies": { "firebase-admin": "^12.4.0", "firebase-functions": "^6.0.1", "nodemailer": "^6.9.15" } }
Debug日志(错误前内容)
Failed to find version of module node: reached end of search path src/functions/node_modules ✔ functions: Using node@18 from host. Could not find functions.yaml. Must use http discovery Found firebase-functions binary at 'src/functions/node_modules/.bin/firebase-functions' Serving at port 8872 ⬢ functions: Failed to load function definition from source: FirebaseError: User code failed to load. Cannot determine backend specification
调试更新
进一步调试发现,模拟器启动时会执行以下命令加载函数代码:
node src/functions/node_modules/.bin/firebase-functions src/functions
目前猜测问题可能出在两个方向:
firebase-tools不再生成functions.yaml(可能是旧版本遗留的兼容性问题)firebase-functions的Node进程崩溃,导致无法在firebase-tools预期的10秒超时内返回函数代码信息
内容的提问来源于stack exchange,提问作者cmjordan
相关产品推荐
相关产品推荐

