我正在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相关问答推荐

DocuSign:调用createEntaine时,RequestJWTApplicationToken返回401 AUTHORIZATION_INVALID_TOKEN

Mongoose-不会更新数组中的属性值

Gmail API获取附件PDF未正确呈现.我遗漏了什么?

验证器功能在mongoose 中不起作用

函数声明中的异步在没有等待的函数中做什么?

Axios TypeError:将循环 struct 转换为 JSON

数据未被中间件解析

错误:无法为 /blog 收集页面数据并且在 object.fetch 处获取失败

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

如何更改NodeJS中的堆栈大小限制?

容器之间的 Docker HTTP 请求

在 Node.js 与 Cron 作业(job)中设置间隔?

如何在 Node.js 中等待子进程完成

在 express 中添加故意延迟

使用 pg-promise 进行多行插入

按日期时间字段获取最新的 MongoDB 记录

如何在离线时安装 npm 包?

安装Node.js 安装n 安装Node.js?

fs.createWriteStream 不会立即创建文件?

要求('babel/register')不起作用