reactjs - NextJS 在 Firebase Functions Deploy 上引发错误
问题描述
TLDR;我正在关注 NextJS 中使用 Firebase 的示例,并且通过最小的更改我无法推送到 Firebase。
我正在关注 NextJS with-firebase-hosting-and-typescript示例,并根据#8893的帮助。
我将deploy
脚本更改package.json
为cross-env NODE_ENV=production firebase deploy
.
我还将conf
值更改functions/index.ts
为
conf: {
distDir: `${path.relative(process.cwd(), __dirname)}/../functions/next`
}
当我将应用程序部署到 firebase 时,我现在收到一个错误
部署错误。为您的函数设置执行环境时出错。请在几分钟后再次尝试部署。
我做了一些调试,如果我注释掉这一行
const app = next({ dev, conf: { distDir: `${path.relative(process.cwd(), __dirname)}/../functions/next` }
})
在 中functions/index.ts
,那么这些功能将部署得很好。所以,问题似乎与next()
这是 的代码functions/index.ts
,这会引发错误。
import * as functions from 'firebase-functions'
import next from 'next'
import * as path from 'path'
const appSetup = {
dev: process.env.NODE_ENV !== 'production',
conf: { distDir: `${path.relative(process.cwd(), __dirname)}/../functions/next` }
}
console.log("appSetup: ", appSetup)
const app = next(appSetup)
// const handle = app.getRequestHandler()
export const nextApp = functions.https.onRequest(async(req, res) => {
// return app.prepare().then(() => handle(req, res))
return res.send({ status: "Hello from Firebase!, nextApp" })
})
这是的代码functions/index.ts
,这不会引发错误
import * as functions from 'firebase-functions'
import next from 'next'
import * as path from 'path'
const appSetup = {
dev: process.env.NODE_ENV !== 'production',
conf: { distDir: `${path.relative(process.cwd(), __dirname)}/../functions/next` }
}
console.log("appSetup: ", appSetup)
// const app = next(appSetup)
// const handle = app.getRequestHandler()
export const nextApp = functions.https.onRequest(async(req, res) => {
// return app.prepare().then(() => handle(req, res))
return res.send({ status: "Hello from Firebase!, nextApp" })
})
在package.json
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.0",
"next": "^9.3.5",
"react": "16.13.1",
"react-dom": "16.13.1"
解决方案
对于任何在同一问题上苦苦挣扎的人。解决方法是functions/index.ts
我需要更换
conf: { distDir: `${path.relative(process.cwd(), __dirname)}/../functions/next` }
至
conf: { distDir: `${path.relative(process.cwd(), __dirname)}/next` }
推荐阅读
- office-js - Excel 中已注册的事件处理程序在已发布的旁加载加载项上停止触发
- django - 无法连接到服务器错误 Google App Engine 静态文件问题
- javascript - 为什么在函数有效的 JavaScript 中定义分块对象(因为缺少更好的术语)?
- php - 如何在php套接字中连续运行server.php
- visual-studio - 无法在 Visual Studio 属性中加载 android 清单(尝试加载页面时发生错误。索引超出了数组的范围。)
- javascript - JavaScript + Ajax - 如何用 JavaScript 的 Ajax 伪装 IP 地址?
- python - 为什么两种方式结果不同?(Django Rest Framework 3.9)
- pandas - 将列的数据类型从对象转换为数值
- java - 每隔一小时的 Java Sync 值
- php - php中的动态多级菜单