我正在try 部署我的下一个.Azure上的js(SSR).

我有一个发布整个根文件夹的构建管道(不仅仅是静态应用的下一个文件夹)

trigger:
  - main

pool:
  vmImage: "ubuntu-latest"

# Set variables
variables:
  directory: .

steps:
  - task: NodeTool@0
    inputs:
      versionSpec: "16.x"
    displayName: "Install Node.js"

  - script: yarn
    displayName: "Install dependencies"
    workingDirectory: $(directory)
    
  - task: Cache@2
    displayName: 'Cache .next/cache'
    inputs:
      key: next | $(Agent.OS) | yarn.lock
      path: '$(System.DefaultWorkingDirectory)/.next/cache'

  - script: yarn build
    displayName: "Build for production"
    workingDirectory: $(directory)

  - task: CopyFiles@2
    displayName: "Copy files"
    inputs:
      sourceFolder: "$(directory)"
      Contents: "**/*"
      TargetFolder: "$(Build.ArtifactStagingDirectory)"
      cleanTargetFolder: true

  - task: ArchiveFiles@2
    displayName: "Archive files"
    inputs:
      rootFolderOrFile: "$(Build.ArtifactStagingDirectory)"
      includeRootFolder: false
      archiveType: zip
      archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
      replaceExistingArchive: true

  - task: PublishBuildArtifacts@1
    displayName: "Publish build artifacts"
    inputs:
      pathtoPublish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip

我在项目根文件夹中还有一个文件ecosystem.config.js,其中包含内容(如this answer所述)

module.exports = {
  apps: [
    {
      name: "app-name",
      script: "./node_modules/.bin/next",
      args: "start -p " + (process.env.PORT || 3000),
      watch: false,
      autorestart: true,
    },
  ],
};

如前所述,构建管道将整个根文件夹发布为发布管道的.zip个工件.

我有一个发布管道,它将工件部署到应用程序服务,并运行启动命令(从same answerMicrosoft docs)

pm2 start /home/site/wwwroot/ecosystem.config.js --no-daemon

package.json脚本部分

"scripts": {
  "dev": "next dev",
  "build": "next build",
  "start": "next start",
  "lint": "next lint"
}

我可以看到构建和发布管道都已成功完成,并且我可以看到根项目文件夹中的文件位于/home/site/wwwroot中,但当我访问站点时,我得到的只是

Site error message

指向诊断资源的链接没有提供太多的细节,但如果我判断应用程序服务中docker容器的日志(log),我会看到

2022-05-16T11:03:07.083870878Z 2022-05-16T11:03:07: PM2 log: App [app-name:0] exited with code [1] via signal [SIGINT]
2022-05-16T11:03:07.085484100Z 11:03:07 PM2               | App [app-name:0] exited with code [1] via signal [SIGINT]
2022-05-16T11:03:07.086237210Z 2022-05-16T11:03:07: PM2 log: App [app-name:0] starting in -fork mode-
2022-05-16T11:03:07.087102722Z 11:03:07 PM2               | App [app-name:0] starting in -fork mode-
2022-05-16T11:03:07.103212737Z 2022-05-16T11:03:07: PM2 log: App [app-name:0] online
2022-05-16T11:03:07.105379766Z 11:03:07 PM2               | App [app-name:0] online
2022-05-16T11:03:07.370010000Z 11:03:07 0|app-name        | Error: Cannot find module '../build/output/log'
2022-05-16T11:03:07.372651936Z 11:03:07 0|app-name        | Require stack:
2022-05-16T11:03:07.372950840Z 11:03:07 0|app-name        | - /home/site/wwwroot/node_modules/.bin/next
2022-05-16T11:03:07.373244644Z 11:03:07 0|app-name        |     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-05-16T11:03:07.373521147Z 11:03:07 0|app-name        |     at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:61:29)
2022-05-16T11:03:07.373779851Z 11:03:07 0|app-name        |     at require (node:internal/modules/cjs/helpers:94:18)
2022-05-16T11:03:07.374053954Z 11:03:07 0|app-name        |     at Object.<anonymous> (/home/site/wwwroot/node_modules/.bin/next:7:35)
2022-05-16T11:03:07.375460973Z 11:03:07 0|app-name        |     at Module._compile (node:internal/modules/cjs/loader:1101:14)
2022-05-16T11:03:07.375473673Z 11:03:07 0|app-name        |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
2022-05-16T11:03:07.375477573Z 11:03:07 0|app-name        |     at Module.load (node:internal/modules/cjs/loader:981:32)
2022-05-16T11:03:07.375480873Z 11:03:07 0|app-name        |     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-05-16T11:03:07.375485473Z 11:03:07 0|app-name        |     at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
2022-05-16T11:03:07.375693476Z 11:03:07 0|app-name        |     at Module._compile (node:internal/modules/cjs/loader:1101:14) {
2022-05-16T11:03:07.376825291Z 11:03:07 0|app-name        |   code: 'MODULE_NOT_FOUND',
2022-05-16T11:03:07.377099895Z 11:03:07 0|app-name        |   requireStack: [ '/home/site/wwwroot/node_modules/.bin/next' ]
2022-05-16T11:03:07.377376699Z 11:03:07 0|app-name        | }
2022-05-16T11:03:07.378681516Z 2022-05-16T11:03:07: PM2 log: App [app-name:0] exited with code [1] via signal [SIGINT]
2022-05-16T11:03:07.379377325Z 2022-05-16T11:03:07: PM2 log: Script /home/site/wwwroot/node_modules/.bin/next had too many unstable restarts (16). Stopped. "errored"
2022-05-16T11:03:07.384267191Z 11:03:07 PM2               | App [app-name:0] exited with code [1] via signal [SIGINT]
2022-05-16T11:03:07.384723497Z 11:03:07 PM2               | Script /home/site/wwwroot/node_modules/.bin/next had too many unstable restarts (16). Stopped. "errored"

有人知道如何从这里开始吗?

提前感谢!

推荐答案

我解决了这个问题,我把ecosystem.config.js年的创业脚本改为

./node_modules/next/dist/bin/next

而不是

./node_modules/.bin/next

我的新ecosystem.config.js

module.exports = {
  apps: [
    {
      name: "app-name",
      script: "./node_modules/next/dist/bin/next",
      args: "start -p " + (process.env.PORT || 3000),
      watch: false,
      autorestart: true,
    },
  ],
};

Node.js相关问答推荐

使用HTTPS从NodeJS 17.9.1升级到18.0.0后,SignalR连接失败

聚合发布/订阅消息

填充函数在Node.js和MongoDB中不起作用

在 puppeteer 中从 pdf 中删除 about:blank 和 date-time

为什么 docker 容器内的应用程序无法访问它自己的 API 端点?

如何设置 Puppeteer Select 器的唯一性?

yarn 安装失败,因为 node-gyp 正在寻找过时的 node 版本标头

在 .htaccess 中从非 www 切换到 www 后如何解决无法访问该站点?

如何通过node下载zip并直接解压zip?

如何使用 node.js 将两个或多个 API 请求组合成一个端点并表达

Jest - SyntaxError: 不能在@nestjs/axios 的模块外使用 import 语句

如何在不使用位置运算符 $ 的情况下更新 mongodb 文档中数组中的嵌套文档?

MERN 堆栈项目中的 React [create-react-app] 正在提供依赖项

cURL 和 shell 任务

User.findOrCreate 函数是做什么的,什么时候在Passport 中调用它?

nodejs - 如何读取和输出 jpg 图像?

在 Node 中连接和缩小 JS 文件

如何从 Node.js 中的 URL 获取

如何在express 中设置默认路径(路由前缀)?

Mongoose - 验证邮箱语法