1

这是项目结构:

项目结构

应用文件夹结构

我的网站写在 next.js 上。为了使用 next-i18next 和发送电子邮件,有 src/app/server/server.js 。

const express = require("express");
const next = require("next");
const nextI18NextMiddleware = require("next-i18next/middleware");
var bodyParser = require("body-parser");
const nextI18next = require("../i18n");

const port = process.env.PORT || 3000;
const nextApp = next({ dev: process.env.NODE_ENV !== "production" });
const handle = nextApp.getRequestHandler();

nextApp.prepare().then(() => {
  const server = express();

  // parse application/json
  server.use(bodyParser.json());

  const sendMail = require("./sendMail");
  server.use("/api/v1/communicate", sendMail);

  server.use(nextI18NextMiddleware(nextI18next));

  server.get("*", (req, res) => handle(req, res));

  server.listen(port);
  console.log(`> Ready on http://localhost:${port}`);
});

为了在 firebase 上托管应用程序,我在 src/functions/index.js 中使用了 firebase 函数:

const functions = require("firebase-functions");
const next = require("next");

var dev = process.env.NODE_ENV !== "production";
var app = next({ dev, conf: { distDir: "next" } });
var handle = app.getRequestHandler();

exports.next = functions.https.onRequest((req, res) => {
  console.log("File: " + req.originalUrl); // log the page.js file that is being requested
  return app.prepare().then(() => handle(req, res));
});

在项目的根目录中,我有 package.json:

{
  "name": "src",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "install": "yarn build-all",
    "next": "yarn build-firebase && cd \"src/app\" && yarn && yarn dev",
    "preserve": "yarn build-all",
    "serve": "firebase serve",
    "predeploy": "yarn build-all",
    "deploy": "firebase deploy",
    "build-all": "yarn build-next && yarn build-firebase",
    "build-next": "cd \"src/app\" && yarn && yarn build",
    "build-firebase": "cd \"src/functions\" && yarn"
  },
  "engines": {
    "node": "10"
  }
}

当我运行命令时

yarn build-all

我有这个输出:

命令输出1

当我运行命令时

firebase deploy --only functions:next

我有这个输出:

命令输出2

目前,我的问题是我现在不知道如何在 firebase 托管上部署应用程序。不幸的是,我找不到任何可以帮助我理解问题的东西。我会很高兴听到至少一些假设,这可以帮助我理解问题。

先感谢您 !

4

1 回答 1

1

问题已经很老了,但是如果您仍然想知道如何解决此问题,请尝试添加此纱线脚本:

"ignore-engine": "yarn config set ignore-engines true"

并更新您的 build-all cmd:

"build-all": "yarn ignore-engine && yarn build-next && yarn build-firebase"
于 2020-06-15T17:46:18.610 回答