npm - 如何解决 npm 错误代码 : 254 in azure DevOps?

标签 npm azure-devops yaml npm-install cypress

当我尝试将我的 cypress 测试(通过 nodejs 和 .yml)包含到 azure DevOps 中时,出现以下错误:

Npm failed with return code: 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://learn.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 持续集成到 azure devops 中的教程。

# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.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'

最佳答案

根据您在日志中的错误消息: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

关于npm - 如何解决 npm 错误代码 : 254 in azure DevOps?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63808454/

相关文章:

python-3.x - Python3 日志 yaml 配置

git - 使用主机 SSH key 在 DockerFile 中访问私有(private) Git 存储库

javascript - 是否可以通过 URL 从 NPM 下载并安装 JS 文件(不是 NPM 包)?

node.js - npm 无法发布我的模块

azure - Lerna 包和 PublishBuildArtifactsV1 任务

laravel - vagrant laravel 第一次运行出错

javascript - Swagger:第一个枚举值覆盖类型

node.js - 将公共(public)依赖项导入 package.json?

azure - 如何通过 Azure DevOps API 更改拉取请求的目标

azure - 如何在 ADO 管道中使用 Powershell 模块?