node.js - firebase 函数:TypeError:func 不是函数
问题描述
Angular 项目中带有 expressjs 的 firebase-tools 会导致错误:
在我的本地机器! functions: TypeError: func is not a function
上运行时。firebase serve
快递服务器在没有firebase的情况下运行,没有错误,即:运行时node dist/server.js
我使用所有东西的最新版本(Angular、Firebase、express)
日志:
i functions: Beginning execution of "ssr"
> (node:4852) [DEP0005] DeprecationWarning: Buffer() is deprecated due to secur
ity and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), o
r Buffer.from() methods instead.
! functions: TypeError: func is not a function
at runFunction (node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:621:20)
at node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:596:19
at Generator.next (<anonymous>)
at node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:7:71
at new ZoneAwarePromise (dist\server.js:1397:29)
at __awaiter (node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:3:12)
at runFunction (node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:593:12)
at node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:620:15
at Generator.next (<anonymous>)
at node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:7:71
at new ZoneAwarePromise (dist\server.js:1397:29)
at __awaiter (node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:3:12)
at runHTTPS (node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:616:12)
at node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:543:27
at Generator.next (<anonymous>)
at node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:7:71
! Your function was killed because it raised an unhandled error.
服务器.ts:
import "zone.js/dist/zone-node";
import express from "express";
const app = express();
const DIST_FOLDER = join(process.cwd(), "./dist/browser");
const {
AppServerModuleNgFactory,
LAZY_MODULE_MAP,
ngExpressEngine,
provideModuleMap
} = require("./dist/server/main");
app.engine(
"html",
ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [provideModuleMap(LAZY_MODULE_MAP)]
})
);
app.set("view engine", "html");
app.set("views", DIST_FOLDER);
app.use((req, res, next) => {
if (!req.path) req.url = `/{req.url}`;
next();
});
app.get("/api/", (req, res) => {
res.json({ ok:true});
});
// Serve static files from /browser
app.get(
"*.*",
express.static(DIST_FOLDER, {
maxAge: "1y"
})
);
// All regular routes use the Universal engine
app.get("*", (req, res) => {
res.render("index", { req });
});
//app.listen(4200)
export { app }; //for firebase
firebase 功能 ssr:
import * as functions from "firebase-functions";
const app = require("../server");
export const ssr = functions.https.onRequest(app);
更新const app = require('../server')
我通过更改为
修复了此错误const {app} = ...
但现在出现了一个新错误:
i functions: Beginning execution of "ssr"
! functions: TypeError: handler is not a function
at cloudFunction (node_modules\firebase-functions\lib\providers\https.js:49:9)
at runFunction (node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:621:20)
at node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:596:19
at Generator.next (<anonymous>)
at node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:7:71
at new ZoneAwarePromise (node_modules\zone.js\dist\zone-node.js:931:29)
at __awaiter (node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:3:12)
at runFunction (node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:593:12)
at node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:620:15
at Generator.next (<anonymous>)
at node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:7:71
at new ZoneAwarePromise (node_modules\zone.js\dist\zone-node.js:931:29)
at __awaiter (node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:3:12)
at runHTTPS (node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:616:12)
at node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:543:27
at Generator.next (<anonymous>)
! Your function was killed because it raised an unhandled error.
解决方案 我意识到问题在于 webpack 的导出并没有真正导出模块前节点。
解决方案
推荐阅读
- r - ggplot循环中绘图大小的大小写取决于大小写
- c# - 按分组数据拆分列表
- python - 在不使用熊猫的情况下合并和删除两个csv中的重复项
- ios - Swift firebase 获取数据
- android - 仅当用户在 Android 中关闭应用程序时如何显示 FCM 通知?
- ios - 如何严格在第一行的插入处添加按钮中的图像?
- javascript - 如何检测 iframe 之外的父滚动事件 => 获取 iframe-position-fixed-polyfill 工作
- javascript - Jest - DOM 相关和跨 JS 文件单元测试
- laravel - 将 Laravel .env 变量添加到 Vue 组件
- security - 码头包括密码套件