node.js - 使用 Azure DevOps 部署 Node.js 应用程序会导致出现有关缺少模块的错误

标签 node.js npm azure-devops

我正在尝试使用 Azure DevOps 部署我的 Angular 项目。从每个阶段的绿色复选标记来看,构建和部署过程似乎都正确进行。当我尝试访问该网页时,它显示应用程序错误页面,其中包含指向诊断资源的链接。

该项目位于 GitHub 上,在构建过程中从那里提取。最终,在完成所有任务后,应用程序未启动,并且我在诊断资源中收到以下错误:

2019-10-04T11:19:47.004554842Z A P P   S E R V I C E   O N   L I N U X
2019-10-04T11:19:47.004559742Z 
2019-10-04T11:19:47.004564342Z Documentation: http://aka.ms/webapp-linux
2019-10-04T11:19:47.004569042Z NodeJS quickstart: https://aka.ms/node-qs
2019-10-04T11:19:47.004573843Z NodeJS Version : v10.10.0
2019-10-04T11:19:47.004578543Z 
2019-10-04T11:19:47.065230218Z /opt/startup/init_container.sh: line 32: [: ==: unary operator expected
2019-10-04T11:19:47.108722107Z Oryx Version : 0.2.20190730.1, Commit: 4ef0d5854df39c57605e59bb6d255215cc85468a
2019-10-04T11:19:47.109454132Z 
2019-10-04T11:19:47.115741747Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2019-10-04T11:19:47.116226163Z Could not find operation ID in manifest. Generating an operation id...
2019-10-04T11:19:47.116765782Z Build Operation ID: d07e7783-8975-4038-8eaa-4e7987fbfe37
2019-10-04T11:19:47.890841571Z Writing output script to '/opt/startup/startup.sh'
2019-10-04T11:19:47.896506064Z Running #!/bin/sh
2019-10-04T11:19:47.897427996Z 
2019-10-04T11:19:47.897445097Z # Enter the source directory to make sure the script runs where the user expects
2019-10-04T11:19:47.898696539Z cd "/home/site/wwwroot"
2019-10-04T11:19:47.898713540Z 
2019-10-04T11:19:47.899855479Z if [ -z "$PORT" ]; then
2019-10-04T11:19:47.900292094Z         export PORT=8080
2019-10-04T11:19:47.900308195Z fi
2019-10-04T11:19:47.901053620Z 
2019-10-04T11:19:47.901069221Z npm start
2019-10-04T11:19:48.909373625Z 
2019-10-04T11:19:48.909490829Z > appname@0.0.0 start /home/site/wwwroot
2019-10-04T11:19:48.909499129Z > ng serve
2019-10-04T11:19:48.909512530Z 
2019-10-04T11:19:49.177294093Z internal/modules/cjs/loader.js:583
2019-10-04T11:19:49.177326694Z     throw err;
2019-10-04T11:19:49.177333094Z     ^
2019-10-04T11:19:49.177336894Z 
2019-10-04T11:19:49.177340595Z Error: Cannot find module '../lib/init'
2019-10-04T11:19:49.177344395Z     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
2019-10-04T11:19:49.177348395Z     at Function.Module._load (internal/modules/cjs/loader.js:507:25)
2019-10-04T11:19:49.177360595Z     at Module.require (internal/modules/cjs/loader.js:637:17)
2019-10-04T11:19:49.177364695Z     at require (internal/modules/cjs/helpers.js:20:18)
2019-10-04T11:19:49.177368396Z     at Object. (/home/site/wwwroot/node_modules/.bin/ng:25:1)
2019-10-04T11:19:49.177372596Z     at Module._compile (internal/modules/cjs/loader.js:689:30)
2019-10-04T11:19:49.177376196Z     at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
2019-10-04T11:19:49.177379896Z     at Module.load (internal/modules/cjs/loader.js:599:32)
2019-10-04T11:19:49.177383596Z     at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
2019-10-04T11:19:49.177387196Z     at Function.Module._load (internal/modules/cjs/loader.js:530:3)
2019-10-04T11:19:49.188853589Z npm ERR! code ELIFECYCLE
2019-10-04T11:19:49.190238236Z npm ERR! errno 1
2019-10-04T11:19:49.193511748Z npm ERR! appname@0.0.0 start: `ng serve`
2019-10-04T11:19:49.194584885Z npm ERR! Exit status 1
2019-10-04T11:19:49.196721058Z npm ERR! 
2019-10-04T11:19:49.197268977Z npm ERR! Failed at the appname@0.0.0 start script.
2019-10-04T11:19:49.197998301Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-10-04T11:19:49.205773868Z 
2019-10-04T11:19:49.206361388Z npm ERR! A complete log of this run can be found in:
2019-10-04T11:19:49.206880405Z npm ERR!     /root/.npm/_logs/2019-10-04T11_19_49_199Z-debug.log

用于构建和部署阶段的 YML 文件如下:

variables:

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

stages:
- stage: Build
  displayName: Build stage
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)

    steps:
    - task: NodeTool@0
      inputs:
        versionSpec: '10.x'
      displayName: 'Install Node.js'

    - script: |
        npm install -g @angular/cli
        npm install
        npm run build
      displayName: 'npm install and build'

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

    - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
      artifact: drop

- stage: Deploy
  displayName: Deploy stage
  dependsOn: Build
  condition: succeeded()
  jobs:
  - deployment: Deploy
    displayName: Deploy
    environment: $(environmentName)
    pool: 
      vmImage: $(vmImageName)
    strategy:
      runOnce:
        deploy:
          steps:            
          - task: AzureWebApp@1
            displayName: 'Azure Web App Deploy: appname'
            inputs:
              azureSubscription: $(azureSubscription)
              appType: webAppLinux
              appName: $(webAppName)
              runtimeStack: 'NODE|10.10'
              package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip
              startUpCommand: 'npm start'

我尝试运行其他命令来重新安装 npm 或删除 node_modules,但这并没有解决问题。请帮忙,因为我对如何完成这项工作一无所知。

最佳答案

  1. 在本地拉取最新版本
  2. 删除package-lock.json
  3. 运行npm install
  4. 推送新的 package-lock.json
  5. 检查 Azure DevOps

关于node.js - 使用 Azure DevOps 部署 Node.js 应用程序会导致出现有关缺少模块的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58235784/

相关文章:

node.js - (更新解决方案)Express Web 应用程序服务抛出 "SyntaxError: Unexpected token >"

javascript - 有没有 Javascript depipe 方法?类似于绑定(bind)或调用,但用于取消管道原型(prototype)

shell - 通过 PM2 将环境变量传递给 NextJS

Azure-Pipeline Build 结果为 : The current . NET SDK 不支持定位 .NET Core 3.1

node.js - sh : husky: command not found

node.js - 使用 Express 传递 json 正文调用现有 API

meteor - choco Meteor 安装 - 自定义/不同的安装位置

node.js - npm、nodejs、package.json、模块版本不匹配。预期48,得到51

azure - 从另一个管道触发 Azure DevOps 管道

tfs - VSO : Single project with a tiered area structure?