Firebase deploy --only hosting error with next.js latest

jckbn6z7  于 2023-08-04  发布在  其他
关注(0)|答案(2)|浏览(95)

我用这个命令创建了一个next.js项目:npx create-next-app@latest testdemo并选择这些选项来创建:
x1c 0d1x的数据
在那之后,我在本地运行了它,它运行得很好,
build也很好,build create .next文件夹,在其中,它创建了server/app/index.html和许多其他文件。
然后我想把它部署到firebase主机,为此我已经登录到firebase控制台,然后
我已经点击了firebase init命令并选择了这些选项:



之后,firebase.json看起来像:

{
  "hosting": {
    "source": ".",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "frameworksBackend": {
      "region": "us-central1"
    }
  }
}

字符串
然后我运行这个命令:

firebase deploy --only hosting


命令工作正常,但它的网址是给我看这个:



我想知道我在这里做错了什么,为什么我不能在那个URL中看到next.js应用程序。
我尝试过构建和部署next.js应用程序到firebase主机,但遇到了一些错误。我期待着从有经验的人那里得到我问题的答案。

zi8p0yeb

zi8p0yeb1#

如果你需要服务器端代码,你需要使用函数。如果你只有一个前端而不使用API路由,你可以导出静态站点。
有关功能,请查看-https://github.com/vercel/next.js/tree/canary/examples/with-firebase-hosting
对于静态导出,更新next.config.js以包括output: 'export'

// next.config.js
/**
 * @type {import('next').NextConfig}
 */
const nextConfig = {
  output: 'export',
  // Optional: Add a trailing slash to all paths `/about` -> `/about/`
  // trailingSlash: true,
  // Optional: Change the output directory `out` -> `dist`
  // distDir: 'dist',
}
 
module.exports = nextConfig

字符串

azpvetkf

azpvetkf2#

Next.js应用程序需要在服务器上运行代码,这需要使用Cloud Functions。由于当您告诉Firebase CLI部署--only hosting时,这些不会被部署,因此您最终会看到Firebase Hosting的默认欢迎页面。
所以运行firebase deploy不带选项,或者firebase deploy --only hosting,functions

相关问题