3

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://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

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://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'
ABC123
  • 269
  • 2
  • 6
  • 13
  • Can you post the complete log of the error? – Diogo Rocha Sep 09 '20 at 09:19
  • 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. Sep 09 '20 at 15:01
  • i added the yaml. but how can i check if the package.json is located at the right point in azure? – ABC123 Sep 10 '20 at 13:13
  • @KevinLu-MSFT it is still open – ABC123 Sep 14 '20 at 08:52
  • @ABC123 How about the issue? Does the answer below resolved your question? Just a remind of [this](https://stackoverflow.com/help/someone-answers) . – Walter Sep 22 '20 at 07:49
  • Unfortunately not – ABC123 Sep 23 '20 at 09:07
  • @ABC123 Would you please let me know the latest information about this issue? The error message you mentioned last time is:Details Job 1 error(s), 1 warning(s) Error: ENOENT: no such file or directory, stat'/home/vsts/work/1/s/cypressio'. Are you still having this issue? – Walter Sep 23 '20 at 09:12
  • yes its all the same – ABC123 Oct 01 '20 at 13:12
  • @ABC123 Can you provide a screenshot of your folder structure? Especially the location of package.json. Please also make sure that the branch you build is correct. – Walter Oct 05 '20 at 08:45

1 Answers1

2

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
Mengdi Liang
  • 17,577
  • 2
  • 28
  • 35
Walter
  • 2,640
  • 1
  • 5
  • 11
  • 1
    i changed the path to the package.json file but i am getting the same error code – ABC123 Sep 14 '20 at 08:20
  • @ABC123 I can reproduce the same error message on my side if my working folder is incorrect. It works well after changing it. Can you share the following things if you still have this issue? 1.The configuration of your npm task. 2.Your build logs. 3.The location of package.json in the repo. Thank you. – Walter Sep 14 '20 at 08:47
  • The location of my package.json is the folder /cypressio in my repo my npm settings: `- task: Npm@1 inputs: command: 'custom' customCommand: 'run test' continueOnError: true` – ABC123 Sep 14 '20 at 09:59
  • According to the location of your package.json,the correct configuration of your npm task should be: - task: Npm@1 inputs: command: 'custom' workingDir: '$(Build.SourcesDirectory)/cypressio' customCommand: 'run test' continueOnError: true – Walter Sep 14 '20 at 10:10
  • now im getting the following error: Details Job 1 error(s), 1 warning(s) Error: ENOENT: no such file or directory, stat '/home/vsts/work/1/s/cypressio' – ABC123 Sep 14 '20 at 10:37
  • @ABC123 This means that the name of your folder is incorrect. Please double check your folder name for any spelling errors. Please share a screenshot about your location of package.json if you still have this issue. I look forward to your reply. – Walter Sep 15 '20 at 06:12
  • @ABC123 Hi friend, is there any update for this issue? Feel free to let me know if you're still blocked, I'll try my best to help :) – Walter Sep 16 '20 at 06:48
  • ah i see now why that does not work. my repo is at develop but i tried to automate cypress in the master branch – ABC123 Sep 16 '20 at 07:56