部署到 Vercel 的 Express 应用程序缺少依赖项

问题描述 投票:0回答:1

好的,所以我创建了一个简单的 API,用于恢复存储在 Firebase Storage 上的文件,并将其部署到 Vercel 以供商品使用,但是部署完成后,日志中会显示下一个错误:

firebase/storage

在使用 ExpressJS 的无服务器 Vercel 部署上使用 Firebase 存储是否有问题?这是我第一次将无服务器 Express 应用程序部署到使用 Firebase 服务的 Vercel,因此我没有遇到过这种奇怪的错误。有人遇到过这些类型错误吗?

这是我的代码和导入的端点

Cannot find module '../deps/dicer/lib/Dicer' Require stack: - /var/task/node_modules/@fastify/busboy/lib/main.js - /var/task/node_modules/undici/lib/fetch/body.js - /var/task/node_modules/undici/lib/fetch/response.js - /var/task/node_modules/undici/index.js - /var/task/node_modules/@firebase/storage/dist/index.node.cjs.js - /var/task/node_modules/firebase/storage/dist/index.cjs.js - /var/task/index.js - /var/task/___now_launcher.js - /var/runtime/index.mjs Did you forget to add it to "dependencies" in `package.json`? INIT_REPORT Init Duration: 517.22 ms Phase: invoke Status: error Error Type: Runtime.ExitError Error: Runtime exited with error: exit status 1

还有我的
const app = require('express')(); const cors = require('cors'); const firebaseApp = require('./config/firebase'); const { getDownloadURL, getStorage, listAll, ref } = require('firebase/storage'); require('dotenv').config(); const storage = getStorage(firebaseApp); app.use(cors()); app.get("/img", async (req, res) => { const storageRef = ref(storage, "img"); const images = await listAll(storageRef); const imgs = await Promise.all( images.items.map((item) => getDownloadURL(item)) ); return res.status(200).json({ ok: true, message: "Images fetched successfully", data: imgs, }); });

vercel.json


firebase express google-cloud-storage firebase-storage vercel
1个回答
0
投票

我不知道

{ "version": 2, "builds": [ { "src": "index.js", "use": "@now/node" } ], "routes": [ { "src": "/(.*)", "dest": "index.js" } ] }

已被

弃用
,而是支持@now/node运行时(如
此处
所指定),因此通过更改为@vercel/node”解决了该问题。
我希望有类似问题的人会发现这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.