5
votes

I'm trying to configure CI/CD on VSTS for an angular application. But the build is getting failed due to above mentioned error. So, there's two npm tasks;

  • npm install - executes successfully

  • npm run-script build - this one fails

    Here's complete log for second task:

    2018-07-07T00:23:02.3521053Z ##[section]Starting: npm run build

2018-07-07T00:23:02.3525327Z

2018-07-07T00:23:02.3525444Z Task         : npm
2018-07-07T00:23:02.3525589Z Description  : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Package Management.
2018-07-07T00:23:02.3525700Z Version      : 1.0.17
2018-07-07T00:23:02.3525777Z Author       : Microsoft Corporation
2018-07-07T00:23:02.3525891Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613746)
2018-07-07T00:23:02.3525989Z ==============================================================================
2018-07-07T00:23:02.8106804Z [command]C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" --version"
2018-07-07T00:23:03.8647145Z 5.6.0
2018-07-07T00:23:05.7712361Z [command]C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" config list"
2018-07-07T00:23:06.7257653Z ; cli configs
2018-07-07T00:23:06.7258787Z metrics-registry = "https://registry.npmjs.org/"
2018-07-07T00:23:06.7260115Z scope = ""
2018-07-07T00:23:06.7263255Z user-agent = "npm/5.6.0 node/v8.11.3 win32 x64"
2018-07-07T00:23:06.7264469Z 
2018-07-07T00:23:06.7264814Z ; environment configs
2018-07-07T00:23:06.7265449Z cache = "C:\\npm\\cache"
2018-07-07T00:23:06.7266275Z prefix = "C:\\npm\\prefix"
2018-07-07T00:23:06.7266951Z userconfig = "D:\\a\\3\\npm\\1.npmrc"
2018-07-07T00:23:06.7268494Z 
2018-07-07T00:23:06.7269010Z ; builtin config undefined
2018-07-07T00:23:06.7307698Z 
2018-07-07T00:23:06.7309592Z ; node bin location = C:\Program Files\nodejs\node.exe
2018-07-07T00:23:06.7309872Z ; cwd = D:\a\3\s
2018-07-07T00:23:06.7310021Z ; HOME = C:\Users\VssAdministrator
2018-07-07T00:23:06.7310173Z ; "npm config ls -l" to show all defaults.
2018-07-07T00:23:06.7310307Z 
2018-07-07T00:23:06.7311709Z [command]C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" run-script build"
2018-07-07T00:23:07.7555197Z npm ERR! path D:\a\3\s\package.json
2018-07-07T00:23:07.7555647Z npm ERR! code ENOENT
2018-07-07T00:23:07.7555859Z npm ERR! errno -4058
2018-07-07T00:23:07.7556046Z npm ERR! syscall open
2018-07-07T00:23:07.7556221Z npm ERR! enoent ENOENT: no such file or directory, open 'D:\a\3\s\package.json'
2018-07-07T00:23:07.7556406Z npm ERR! enoent This is related to npm not being able to find a file.
2018-07-07T00:23:07.7556583Z npm ERR! enoent 
2018-07-07T00:23:07.7556696Z 
2018-07-07T00:23:07.7556849Z npm ERR! A complete log of this run can be found in:
2018-07-07T00:23:07.7557018Z npm ERR!     C:\npm\cache\_logs\2018-07-07T00_23_07_693Z-debug.log
2018-07-07T00:23:07.8410994Z Found npm debug log, make sure the path matches with the one in npm's output: C:\npm\cache\_logs\2018-07-07T00_23_07_693Z-debug.log
2018-07-07T00:23:07.8411205Z 0 info it worked if it ends with ok
2018-07-07T00:23:07.8411317Z 1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
2018-07-07T00:23:07.8411464Z 1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
2018-07-07T00:23:07.8411575Z 1 verbose cli   'run-script',
2018-07-07T00:23:07.8411667Z 1 verbose cli   'build' ]
2018-07-07T00:23:07.8412548Z 2 info using [email protected]
2018-07-07T00:23:07.8412687Z 3 info using [email protected]
2018-07-07T00:23:07.8412805Z 4 verbose stack Error: ENOENT: no such file or directory, open 'D:\a\3\s\package.json'
2018-07-07T00:23:07.8412915Z 5 verbose cwd D:\a\3\s
2018-07-07T00:23:07.8413007Z 6 verbose Windows_NT 10.0.14393
2018-07-07T00:23:07.8413155Z 7 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run-script" "build"
2018-07-07T00:23:07.8413285Z 8 verbose node v8.11.3
2018-07-07T00:23:07.8413373Z 9 verbose npm  v5.6.0
2018-07-07T00:23:07.8413474Z 10 error path D:\a\3\s\package.json
2018-07-07T00:23:07.8413567Z 11 error code ENOENT
2018-07-07T00:23:07.8413654Z 12 error errno -4058
2018-07-07T00:23:07.8413740Z 13 error syscall open
2018-07-07T00:23:07.8414697Z 14 error enoent ENOENT: no such file or directory, open 'D:\a\3\s\package.json'
2018-07-07T00:23:07.8414808Z 15 error enoent This is related to npm not being able to find a file.
2018-07-07T00:23:07.8414912Z 16 verbose exit [ -4058, true ]
2018-07-07T00:23:07.8414968Z 
2018-07-07T00:23:07.8459901Z ##[error]Error: Npm failed with return code: 4294963238
2018-07-07T00:23:07.8486587Z ##[section]Finishing: npm run build

Here's the screenshot of that log:

screenshot

I saw this article but they are also saying that it's an issue in CI. Please let us if anyone has faced the similar issue and got any success

2
The error message states ENOENT: no such file or directory, open 'D:\a\3\s\package.json'. Have you validated that the file exists?Daniel Mann
@DanielMann Yes, I verified that the file doesn't exist. In fact, I have only C drive on my system, there's no D drive.Gaurav Krishn
That's not your system. That's the hosted build agent. D:\a\3\s is the root directory that the repo is synchronized to. Do you have a package.json file in the root of your repo?Daniel Mann
In the Build definition on the Npm build task, what you entered on "Working folder with package.json"?Shayki Abramczyk
@ShaykiAbramczyk, I followed this article, so left it blank.Gaurav Krishn

2 Answers

1
votes

I was also facing a similar error in my Azure DevOps Build pipeline in the build step.

2019-01-07T10:14:37.3232741Z 24 verbose exit [ 1, true ] 2019-01-07T10:14:37.3232816Z 2019-01-07T10:14:37.3286590Z

[error]Error: Npm failed with return code: 1 2019-01-07T10:14:37.3309955Z ##[section]Finishing: npm build

My issue was that I had set the Agent pool as Hosted instead of Hosted VS2017. After changing the same as follows, the build was getting successful.

enter image description here

Hope it helps.

Update:

As per this post, now we have a new hosted pool called Azure Pipelines to replace all the other hosted pools - Hosted, Hosted VS2017, Hosted Ubuntu 1604, Hosted Windows 2019 with VS2019, Hosted macOS, and Hosted macOS High Sierra. So you should select Azure Pipelines.

0
votes

Your files are probably in $(System.DefaultWorkingDirectory)/ you should use it as your "Working folder with package.json".

So far, I've figured that Azure Pipelines have two "special" / predefined directories: $(System.DefaultWorkingDirectory) and $(Build.ArtifactStagingDirectory), whose values are both set as env parameters.

Try using a script step to print out the contents of ./, $(System.DefaultWorkingDirectory)/ and $(Build.ArtifactStagingDirectory)/; it will help you locate your files and figure out where you should run your commands.