如何在Azure DevOps中解决npm错误代码:254?

时间:2020-09-09 09:12:45

标签: npm azure-devops yaml npm-install cypress

当我尝试将我的赛普拉斯测试(通过nodejs和.yml)包括到天蓝色的DevOps中时,出现以下错误:

Npm失败,返回码:254

这是什么意思,我该如何解决?

我的完整日志在这里:

Starting: Npm
==============================================================================
Task         : npm
Description  : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
Version      : 1.174.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/npm
==============================================================================
SYSTEMVSSCONNECTION exists true
SYSTEMVSSCONNECTION exists true
/opt/hostedtoolcache/node/10.22.0/x64/bin/npm --version
6.14.6
/opt/hostedtoolcache/node/10.22.0/x64/bin/npm config list
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.14.6 node/v10.22.0 linux x64"

; environment configs
userconfig = "/home/vsts/work/1/npm/2560.npmrc"

; node bin location = /opt/hostedtoolcache/node/10.22.0/x64/bin/node
; cwd = /home/vsts/work/1/s
; HOME = /home/vsts
; "npm config ls -l" to show all defaults.

/opt/hostedtoolcache/node/10.22.0/x64/bin/npm run test
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/vsts/work/package.json
npm ERR! errno -2

second part of log data

我使用以下YAML: 为了创建这个Yaml,我使用了一个将Cypress持续集成到天蓝色devops中的教程。

# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

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

- script: |
    npm install
  displayName: 'npm install'

- task: Npm@1
  inputs:
    command: 'custom'
    customCommand: 'run test'
  continueOnError: true

- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'JUnit'
    testResultsFiles: '*.xml'
    searchFolder: '$(System.DefaultWorkingDirectory)/cypress/reports/junit'
    mergeTestResults: true
    testRunTitle: 'Publish Test Results'

1 个答案:

答案 0 :(得分:1)

根据日志中的错误消息:ENOENT: no such file or directory, open ‘/home/vsts/work/package.json’,npm无法找到package.json文件。请检查您的package.json位于哪个文件夹。例如:

enter image description here

我的package.json位于web / app文件夹中。我需要在npm任务中将此文件夹设置为工作文件夹。

enter image description here

这是我的npm任务的配置:

- task: Npm@1
  inputs:
    command: 'custom'
    workingDir: '$(Build.SourcesDirectory)/web/app'
    customCommand: 'run test'
  continueOnError: true