NextJS在Firebase Functions Deploy上引发错误



TLDR;我以使用Firebase的NextJS中的一个例子为例,只要进行最小的更改,我就无法推送到Firebase。

我遵循NextJS的firebase托管和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"

适用于遇到同样问题的任何人。修复是functions/index.ts中的行

我需要更换

conf: { distDir: `${path.relative(process.cwd(), __dirname)}/../functions/next` }

conf: { distDir: `${path.relative(process.cwd(), __dirname)}/next` }

相关内容

  • 没有找到相关文章

最新更新