【发布时间】:2020-04-18 20:34:42
【问题描述】:
TLDR;我正在关注 NextJS 中使用 Firebase 的示例,并且通过最小的更改我无法推送到 Firebase。
我正在关注 NextJS with-firebase-hosting-and-typescript 示例,并根据 #8893 的帮助。
我将package.json 中的deploy 脚本更改为cross-env NODE_ENV=production firebase deploy。
我还将functions/index.ts 中的conf 值更改为
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"
【问题讨论】:
-
在 Stack Overflow 上,请不要显示文本或代码的图片。将文本复制到问题本身并设置格式,以便于阅读、复制和搜索。
-
@DougStevenson 抱歉,现在已修复。
标签: reactjs typescript firebase google-cloud-functions next.js