Angular build error on Azure DevOps with powershell script - powershell

I prepared a powershell script in azure devops build pipeline to create an artifact, but when I start build queue, I get an error which is below.
The build command requires to be run in an Angular project, but a
project definition could not be found.
Can someone help me please.
Powershell script:
npm install
npm install -g typescript
npm install -g #angular/cli
ng build --configuration=production
This is all the result of powershell script:
##[section]Starting: PowerShell Script
==============================================================================
Task : PowerShell
Description : Run a PowerShell script on Windows, macOS, or Linux.
Version : 2.148.0
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
==============================================================================
Generating script.
========================== Starting Command Output ===========================
##[command]"C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'd:\a\_temp\90129c3e-4840-41d7-895c-2f9c8f6e5968.ps1'"
npm WARN saveError ENOENT: no such file or directory, open 'D:\a\1\s\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'D:\a\1\s\package.json'
npm WARN s No description
npm WARN s No repository field.
npm WARN s No README data
npm WARN s No license field.
up to date in 5.231s
found 0 vulnerabilities
C:\npm\prefix\tsc -> C:\npm\prefix\node_modules\typescript\bin\tsc
C:\npm\prefix\tsserver -> C:\npm\prefix\node_modules\typescript\bin\tsserver
+ typescript#3.4.5
updated 1 package in 2.063s
C:\npm\prefix\ng -> C:\npm\prefix\node_modules\#angular\cli\bin\ng
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.2.9 (node_modules\#angular\cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ #angular/cli#7.3.9
added 295 packages from 180 contributors in 88.373s
The build command requires to be run in an Angular project, but a project definition could not be found.
##[error]PowerShell exited with code '1'.
##[section]Finishing: PowerShell Script

As the error said, you try to run ng build not in the project folder.
You need to run cd path/to/project-folder before.
Another option, in the Azure DevOps PowerShell task there is a option to specify "Working Directory" so enter there the project path.

Related

Vercel 127 Error deploying vercel application

I'm trying to deploy on vercel, before it was working fine until I added a map library called leaflet and now it's giving an error in the deploy.. I tried to run npm run build in the terminal but still an error.
[10:00:20.566] Cloning github.com/daviroquedev/ride (Branch: master, Commit: 7e7d760)
[10:00:21.284] Cloning completed: 717.186ms
[10:00:21.853] Looking up build cache...
[10:00:22.163] Build Cache not found
[10:00:22.217] Running "vercel build"
[10:00:22.881] Vercel CLI 28.4.2
[10:00:23.187] Installing dependencies...
[10:00:23.831] npm ERR! must provide string spec
[10:00:23.834]
[10:00:23.835] npm ERR! A complete log of this run can be found in:
[10:00:23.835] npm ERR! /vercel/.npm/_logs/2022-09-27T13_00_23_618Z-debug-0.log
[10:00:23.850] Detected `package-lock.json` generated by npm 7+...
[10:00:23.850] Running "npm run build"
[10:00:24.243]
[10:00:24.243] > ride#0.0.0 build
[10:00:24.244] > vite build
[10:00:24.244]
[10:00:24.251] sh: vite: command not found
[10:00:24.259] Error: Command "npm run build" exited with 127
Build Failed
Command "npm run build" exited with 127
PACKAGE.JSON

Appveyor: Package content hash validation failed, The package is different than the last restore

I would like to configure CI in Appveyor for a .net project and I am struggling with following errors:
error NU1403: Package content hash validation failed for System.Collections.NonGeneric.4.3.0. The package is different than the last restore.
Every project restore happens to throw similar thing
There was similar question and one advice was to clear nuget cache.
Whats the best course of action here?
Thanks
Directory.Build.props
<PropertyGroup>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
</PropertyGroup>
Build started
git config --global core.autocrlf true
git clone -q --branch=master https://github.com/User/App.git C:\projects\App
git checkout -qf 7066b969dd7564c573fb5e30fa6600a86c48644f
choco install opencover.portable
Chocolatey v0.11.3
Installing the following packages:
opencover.portable
By installing, you accept licenses for the packages.
Progress: Downloading opencover.portable 4.7.1221... 100%
opencover.portable v4.7.1221 [Approved]
opencover.portable package files install completed. Performing other installation steps.
Downloading opencover.portable
from 'https://github.com/OpenCover/opencover/releases/download/4.7.1221/opencover.4.7.1221.zip'
Progress: 100% - Completed download of C:\Users\appveyor\AppData\Local\Temp\1\chocolatey\opencover.portable\4.7.1221\opencover.4.7.1221.zip (7.76 MB).
Download of opencover.4.7.1221.zip (7.76 MB) completed.
Hashes match.
Extracting C:\Users\appveyor\AppData\Local\Temp\1\chocolatey\opencover.portable\4.7.1221\opencover.4.7.1221.zip to C:\ProgramData\chocolatey\lib\opencover.portable\tools...
C:\ProgramData\chocolatey\lib\opencover.portable\tools
ShimGen has successfully created a shim for OpenCover.Console.exe
ShimGen has successfully created a shim for OpenCover.Simple.Target.exe
ShimGen has successfully created a shim for OpenCover.Simple.Target.exe
The install of opencover.portable was successful.
Software installed to 'C:\ProgramData\chocolatey\lib\opencover.portable\tools'
Chocolatey installed 1/1 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Did you know the proceeds of Pro (and some proceeds from other
licensed editions) go into bettering the community infrastructure?
Your support ensures an active community, keeps Chocolatey tip-top,
plus it nets you some awesome features!
https://chocolatey.org/compare
choco install codecov
Chocolatey v0.11.3
Installing the following packages:
codecov
By installing, you accept licenses for the packages.
Progress: Downloading codecov 1.13.0... 100%
codecov v1.13.0 [Approved]
codecov package files install completed. Performing other installation steps.
Extracting 64-bit C:\ProgramData\chocolatey\lib\codecov\tools/codecov-win7-x64.zip to C:\ProgramData\chocolatey\lib\codecov\tools...
C:\ProgramData\chocolatey\lib\codecov\tools
ShimGen has successfully created a shim for codecov.exe
The install of codecov was successful.
Software installed to 'C:\ProgramData\chocolatey\lib\codecov\tools'
Chocolatey installed 1/1 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
dotnet --version
5.0.403
dotnet restore
Determining projects to restore...
C:\projects\App\Tests\Common.Tests\Common.Tests.csproj : error NU1403: Package content hash validation failed for System.Collections.NonGeneric.4.3.0. The package is different than the last restore. [C:\projects\App\App.sln]
appveyor.xml
version: '1.0.{build}'
image: Visual Studio 2019
branches:
only:
- master
init:
- cmd: git config --global core.autocrlf true
install:
before_build:
- choco install opencover.portable
- choco install codecov
- cmd: dotnet --version
- cmd: dotnet restore
build_script:
- cmd: dotnet build --configuration Release --no-restore
test_script:
- cmd: dotnet test --configuration Release --no-build --no-restore --verbosity minimal --test-adapter-path:. --logger:Appveyor /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:MergeWith="../TestResults/coverage.json" /p:CoverletOutputFormat=lcov
cache:
- '%USERPROFILE%\.nuget\packages -> **\project.json'
- C:\ProgramData\chocolatey\bin -> appveyor.yml
- C:\ProgramData\chocolatey\lib -> appveyor.yml
deploy: off
At Feodor suggestion I added powershell script which removes package.lock.json files and it worked.
before_build:
- choco install opencover.portable
- choco install codecov
- ps: >-
Get-ChildItem .\ -include packages.lock.json -Recurse | foreach ($_) { remove-item $_.fullname -Force }
- cmd: dotnet --version
- cmd: dotnet restore

Azure DevOps Pipeline NPM install task fails with node-gyp build error

I am trying to build an Azure Pipeline in Azure DevOps. The problem is that when a pipeline ran, an error occurred in an npm build task. Could it be that there are some outdated packages in package.json? Or could it be that npm is outdated?
See Step 4 in a tutorial where a pipeline started to run:
https://learn.microsoft.com/en-us/learn/modules/create-a-build-pipeline/6-create-the-pipeline
Screenshot of build tasks in a pipeline:
Raw Log:
2021-12-03T00:13:53.4119601Z ##[section]Starting: Run npm install
2021-12-03T00:13:53.4130006Z ==============================================================================
2021-12-03T00:13:53.4130664Z Task : npm
2021-12-03T00:13:53.4144256Z Description : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
2021-12-03T00:13:53.4145177Z Version : 1.187.0
2021-12-03T00:13:53.4145620Z Author : Microsoft Corporation
2021-12-03T00:13:53.4146127Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/package/npm
2021-12-03T00:13:53.4146868Z ==============================================================================
2021-12-03T00:13:54.7198556Z [command]/usr/local/bin/npm --version
2021-12-03T00:13:55.4151672Z 8.1.0
2021-12-03T00:13:56.0808980Z [command]/usr/local/bin/npm config list
2021-12-03T00:13:56.3808693Z ; "env" config from environment
2021-12-03T00:13:56.3811792Z
2021-12-03T00:13:56.3813271Z userconfig = "/home/vsts/work/1/npm/13.npmrc"
2021-12-03T00:13:56.3814393Z
2021-12-03T00:13:56.3815603Z ; node bin location = /usr/local/bin/node
2021-12-03T00:13:56.3816682Z ; cwd = /home/vsts/work/1/s
2021-12-03T00:13:56.3817732Z ; HOME = /home/vsts
2021-12-03T00:13:56.3819465Z ; Run `npm config ls -l` to show all defaults.
2021-12-03T00:13:56.3822946Z [command]/usr/local/bin/npm install
2021-12-03T00:16:21.9362133Z npm WARN old lockfile
2021-12-03T00:16:21.9365129Z npm WARN old lockfile The package-lock.json file was created with an old version of npm,
2021-12-03T00:16:21.9369471Z npm WARN old lockfile so supplemental metadata must be fetched from the registry.
2021-12-03T00:16:21.9370832Z npm WARN old lockfile
2021-12-03T00:16:21.9372351Z npm WARN old lockfile This is a one-time fix-up, please be patient...
2021-12-03T00:16:21.9373414Z npm WARN old lockfile
2021-12-03T00:16:21.9375186Z npm WARN deprecated uuid#3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
'''
'''
2021-12-03T00:16:22.4541247Z 2732 error | ^
2021-12-03T00:16:22.4542220Z 2732 error /home/vsts/.node-gyp/16.13.0/include/node/node.h:855:3: note: in expansion of macro ‘NODE_MODULE_X’
2021-12-03T00:16:22.4543014Z 2732 error 855 | NODE_MODULE_X(modname, regfunc, NULL, 0) // NOLINT (readability/null_usage)
2021-12-03T00:16:22.4543629Z 2732 error | ^~~~~~~~~~~~~
2021-12-03T00:16:22.4544459Z 2732 error ../src/binding.cpp:358:1: note: in expansion of macro ‘NODE_MODULE’
2021-12-03T00:16:22.4545125Z 2732 error 358 | NODE_MODULE(binding, RegisterModule);
2021-12-03T00:16:22.4545958Z 2732 error | ^~~~~~~~~~~
2021-12-03T00:16:22.4546611Z 2732 error make: *** [binding.target.mk:133: Release/obj.target/binding/src/binding.o] Error 1
2021-12-03T00:16:22.4547249Z 2732 error gyp ERR! build error
2021-12-03T00:16:22.4547826Z 2732 error gyp ERR! stack Error: `make` failed with exit code: 2
2021-12-03T00:16:22.4548944Z 2732 error gyp ERR! stack at ChildProcess.onExit (/home/vsts/work/1/s/node_modules/node-gyp/lib/build.js:262:23)
2021-12-03T00:16:22.4550047Z 2732 error gyp ERR! stack at ChildProcess.emit (node:events:390:28)
2021-12-03T00:16:22.4550822Z 2732 error gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
2021-12-03T00:16:22.4551766Z 2732 error gyp ERR! System Linux 5.11.0-1021-azure
2021-12-03T00:16:22.4552997Z 2732 error gyp ERR! command "/usr/local/bin/node" "/home/vsts/work/1/s/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
2021-12-03T00:16:22.4554136Z 2732 error gyp ERR! cwd /home/vsts/work/1/s/node_modules/node-sass
2021-12-03T00:16:22.4554904Z 2732 error gyp ERR! node -v v16.13.0
2021-12-03T00:16:22.4555635Z 2732 error gyp ERR! node-gyp -v v3.8.0
2021-12-03T00:16:22.4556152Z 2732 error gyp ERR! not ok
2021-12-03T00:16:22.4556664Z 2732 error Build failed with error code: 1
2021-12-03T00:16:22.4557176Z 2733 verbose exit 1
2021-12-03T00:16:22.4557451Z
2021-12-03T00:16:22.4593929Z ##[error]Error: Npm failed with return code: 1
2021-12-03T00:16:22.4611672Z ##[section]Finishing: Run npm install
Why did the error occur in this task?
Microsoft updated their VMs around the 3rd December.
In this change the default node version has changed from 14.x to 16.x.
We found this exact issue when running on node 16.
This won't be a Long term fix - As you'll need to work out why your build doesn't work on Node 16, but in the short term you can add a command which tells the build agent to use version 14 of node.
Presuming you are using the modern YAML build pipelines, try adding the following as the first step in your YAML pipeline:
- task: NodeTool#0
inputs:
versionSpec: '14.x'
This should solve any node 16 issues.
If you use Classic pipelines there may be a way of including this step as it is Microsoft provided, but I'm not sure as I don't use Classic mode.
Note:
If you've run npm version 8 (which comes with node 16) it will probably have upgraded your package-lock.json file to the newer version 2 schema.
This updated package-lock.json won't work with version 14, you'll need to revert the file back to version 1 (which if you don't have an old version in source control can be done by just deleting package-lock and running npm install).
You just need to update your packagelock file with the following actions:
Update your node version from 14 to 16 by installing the 16.13.1 LTS version on the node js website: https://nodejs.org/
Update your version of npm with the command:
npm install -g npm#latest
Update your packagelock.json with the command:
npm install
Push your brand new packagelock.json file to azure then launch again your CI
=> it should be OK ^^
For Classic pipelines users, add task "Node.js tool installer" before your npm install. Node.js tool installer makes it possible to specify node version.
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/node-js?view=azure-devops

VSTS Build is failing with Polymer build

I am running npm,lerna,yarn and bootstrap in my VSTS build definitions via Command line task after running all the above commands I am running npm run build command but while running npm run build command its failing with 'polymer' is not recognized as an internal or external command.Please help me on this.I tried running polymer in a command line passing polymer as a tool and arguments as build even though its failing.Please help me.
Make sure that the polymer-cli npm package is listed in your dev dependencies (at least it sounds like a dev dependency to me) in your package.json. Also make sure you run npm install before you run npm run build. You might have to point your NPM build script to the Polymer package in your node_modules folder because it is not installed globale on the build server

Gulp not working with GitLab runner

I want to get a GitLab runner to work on my laptop (Windows 10) but it does not execute the gulp commands, because "gulp" is not recognized as a script.
This is my .gitlab-ci.yaml
before_script:
- npm install -g gulp-cli
- npm install
cache:
paths:
- node_modules/
stages:
- build
building:
stage: build
tags:
- onpremise
script:
- gulp build
The relevant settings of my config.toml
executor = "shell"
shell = "powershell"
(If I set shell to "cmd" then gulp build is not called at all.)
And the output of my build job in GitLab
$ npm install -g gulp-cli
C:\USERS\_SYSTEM\AppData\Roaming\npm\gulp ->
C:\USERS\_SYSTEM\AppData\Roaming\npm\node_modules\gulp-cli\bin\gulp.js
+ gulp-cli#2.0.1
updated 1 package in 7.67s
$ npm install
up to date in 11.609s
$ gulp build
gulp : The term "gulp" is not recognized as cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
I don't have enough points to comment, so please forgive the guess. I'm suspecting $env:path for your working powershell session is different from the $env:path that your gitlab runner is getting.
You could confirm this by comparing the two by adding $env:path.split(";") to your build script and comparing the output to your working powershell session.
You can also run get-command gulp | select source in the session that works, to locate the gulp file (on my server it's a .cmd file in a personal folder) . You should then be able to add $env:path = $env:path + ";C:\path\to\that\folder" near the top of the build script to resolve the path issue I'm suspecting you have.
Additionally, you may need to install gulp globally if you have not already done so. See https://stackoverflow.com/a/37287770/7674011
Try adding - npm install --save-dev gulp after - npm install -g gulp-cli.