1
votes

When I try to include my cypress tests (via nodejs & .yml) to azure DevOps, I get the following Error:

Npm failed with return code: 254

What does it mean and how can I solve this?

My complete Log is here:

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

I use the following YAML: To create this yaml i used a tutorial for Continuous integration of Cypress into azure 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
Can you post the complete log of the error?Diogo Rocha
Can you also add a snippet from your YAML configuration where the error occurs? It seems like the npm is looking for the package.json in the wrong directory. Pipeline source code (which I assume includes your package.json file) by default should be located at /home/vsts/work/id/s folder, but judging by the error log, the npm is looking for the file at /home/vsts/work.LJ.
i added the yaml. but how can i check if the package.json is located at the right point in azure?ABC123
@ABC123 Is there any update about this ticket? Feel free to let me know if the answer could give you some help. Just a remind of this .Kevin Lu-MSFT
@KevinLu-MSFT it is still openABC123

1 Answers

1
votes

According to your error message in your logs:ENOENT: no such file or directory, open ‘/home/vsts/work/package.json’, npm cannot find your package.json file. Please check which folder your package.json is in. For example:

enter image description here

My package.json is in the web/app folder. I need to set this folder as working folder in npm task.

enter image description here

Here is the configuration of my npm task:

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