【问题标题】:Issue running Next.js on iisnode on Azure Web App在 Azure Web App 上的 iisnode 上运行 Next.js 的问题
【发布时间】:2023-03-20 19:42:01
【问题描述】:

尝试在 Azure Web App 上部署和运行 Next.js。 Azure Web App 在仅使用 Express.js 运行时工作,但只要我调用 nex() 它就会失败。尝试在 Azure 门户中启用错误日志记录,但没有太多用处,只是一般的 500 错误。

以下是有效和无效的方法。

作品:

var express = require('express');
var expressServer = express();

expressServer.get('/', function (req, res) {
    res.send('Express is working on IISNode!');
});

expressServer.listen(process.env.PORT || 8080);

不起作用:

var express = require('express');
const next = require('next');
var expressServer = express();
var app = next();

expressServer.get('/', function (req, res) {
    res.send('Express is working on IISNode!');
});

expressServer.listen(process.env.PORT || 8080);

此时我什至懒得获取请求处理程序,因为 app = next() 失败了。

包.json:

"engines": {
    "node": "9.4.0 || 8.9.x"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.2",   
    "next": "^4.2.3",
    "next-redux-wrapper": "^1.3.5",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-redux": "^5.0.6",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0"
  },
  "devDependencies": {
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "nodemon": "^1.14.11"
  }

编辑: 我认为问题在于next build 需要先运行。我正在寻找是否可以使用 Kudu 之类的东西添加一些后期部署/构建命令。如果您有任何建议,请告诉我。

【问题讨论】:

  • 尝试将"prestart": "next build" 添加到您的package.json 脚本中。
  • 嗨@RVid 您是否设法使 next.js 部署到 azure Web 应用程序正常工作?
  • @Bida 是的,next.js 在 Azure Web App 上运行良好。如果您在 Windows 实例上运行,您还需要您的 web.config 文件。最好创建一个包含更多问题详细信息的新问题。

标签: node.js azure express iisnode next.js


【解决方案1】:

你是对的,你需要先运行next build。

因此,如果您在项目根目录下创建 pages 目录并编辑 package.json 以添加以下内容,这将在 Azure Web App 中工作:

"scripts": {
    "postinstall": "next build"
}

【讨论】:

  • 即使我应用此修复程序,我仍然会收到错误 500,您是否还有其他提示? :)
猜你喜欢
  • 2016-09-01
  • 2017-02-24
  • 1970-01-01
  • 2019-02-28
  • 2020-03-11
  • 1970-01-01
  • 2016-01-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多