Nodejs Azure 部署失败:ENOENT:没有此类文件或目录,stat '/home/site/wwwroot/node_modules/.bin/semver'

23k*_*23k 7 deployment azure node.js azure-pipelines

几天前,我们的生产发布管道开始失败,并出现以下错误:

2020-10-17T00:14:13.1233435Z Omitting next output lines...
2020-10-17T00:14:13.1234108Z Error: ENOENT: no such file or directory, stat '/home/site/wwwroot/node_modules/.bin/semver'
2020-10-17T00:14:13.1234825Z An error has occurred during web site deployment.
2020-10-17T00:14:13.1235127Z Kudu Sync failed
2020-10-17T00:14:13.1235451Z \n/opt/Kudu/Scripts/starter.sh "/home/site/deployments/tools/deploy.sh"
2020-10-17T00:14:13.1265401Z ##[error]Failed to deploy web package to App Service.
2020-10-17T00:14:13.1276348Z ##[error]Error: Package deployment using ZIP Deploy failed. Refer logs for more details.
2020-10-17T00:14:13.6429241Z Successfully updated deployment History at https://{omitted}.scm.azurewebsites.net/api/deployments/{omitted}
2020-10-17T00:14:13.6510314Z ##[section]Finishing: Deploy Azure App Service
Run Code Online (Sandbox Code Playgroud)

管道将成功完成所有测试/脚本+发布删除工件。发布过程启动,但在部署步骤失败,并出现上述错误。

管道图像

我尝试回滚到成功部署的最后一个工作提交但在此步骤中它仍然会失败。

我花了几天时间试图解决这个问题,但没有任何运气。有什么想法会导致这样的事情随机开始发生吗?

如果有助于调试的话,我可以提供有关我们堆栈的其他信息。

编辑

我当前的应用程序设置:

应用程序设置

azure-pipelines.yml

trigger:
- master

variables:

  # Azure Resource Manager connection created during pipeline creation
  azureSubscription: '9690121f-a50b-43c0-8d1b-e8ca6533b2d5'
  
  # Web app name
  webAppName: 'hidden'
  
  # Environment name
  environmentName: 'hidden'

  # 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: '12.x'
      displayName: 'Install Node.js'

    - task: YarnInstaller@3
      inputs:
        versionSpec: '1.22.4'
      displayName: 'Install Yarn'

    - script: |
        yarn install
        yarn build
        yarn test:e2e
      displayName: 'Build and test'
      
    - 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: hidden'
            inputs:
              azureSubscription: '$(azureSubscription)'
              appType: 'webAppLinux'
              appName: '$(webAppName)'
              package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
              runtimeStack: 'NODE|12.x'
              startUpCommand: 'node dist/main'
Run Code Online (Sandbox Code Playgroud)

23k*_*23k 1

我能够通过创建一个新的应用程序服务+一个附加到我们现有存储库的新管道来解决这个问题。

管道+App服务都和老的一模一样。

无论出于何种原因,在新设置上进行部署都有效。这不是我发布的原始问题的精确解决方案,但是,我很高兴现在可以部署代码。如果其他人遇到同样的问题,我建议尝试我所做的同样的事情。