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

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

Related

Running npm install with post install script installing a subdirectory app on github-actions inside docker container fails

I'm getting this error when I try to run npm install in github actions. I have a subfolder which has another project and on postinstall I run the npm install for that subfolder.
Here is the worflow.yml file
name: Install and cache dependencies
on:
workflow_call:
jobs:
install-and-cache-dependencies:
runs-on: ubuntu-latest
# Builder image it contains nodeJs + chromium to run the tests on the ui using puppeteer. We had to build our own because there is no official
# image for this. Version 16.13.0 is the nodeJs version which is installed inside the package.
container:
image: houzy/frontend-builder:16.13.1
env:
NODE_OPTIONS: "--max_old_space_size=4096"
steps:
- uses: actions/checkout#v3
- name: Create hash key
run: touch ${{ hashFiles('**/package-lock.json') }}.hash-file
- name: Install dependencies
run: npm install # npm run install:widgets is run as a post install script
- name: Ivy post-install processing
# This script goes through libraries and adjust them so that they work properly with the Ivy. It stores
# results in node_modules, so it will change whenever some dependencies change.
run: npm run postinstall-ivy
Here is the complete error from Install dependencies step
npm WARN using --force Recommended protections disabled.
npm WARN deprecated urix#0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated source-map-resolve#0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated w3c-hr-time#1.0.2: Use your platform's native performance.now() and performance.timeOrigin.
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.
npm WARN deprecated stable#0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
npm WARN deprecated chokidar#2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated source-map-url#0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated resolve-url#0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated querystring#0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated postinstall-build#5.0.3: postinstall-build's behavior is now built into npm! You should migrate off of postinstall-build and use the new `prepare` lifecycle script with npm 5.0.0 or greater.
npm WARN deprecated chokidar#2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
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.
npm WARN deprecated circular-json#0.3.3: CircularJSON is in maintenance only, flatted is its successor.
npm WARN deprecated #types/swiper#6.0.0: This is a stub types definition. swiper provides its own type definitions, so you do not need this installed.
npm WARN deprecated #types/express-winston#4.0.0: This is a stub types definition. express-winston provides its own type definitions, so you do not need this installed.
npm WARN deprecated sane#4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
npm WARN deprecated #wessberg/ts-evaluator#0.0.27: this package has been renamed to ts-evaluator. Please install ts-evaluator instead
> angular-frontend#1.0.0 postinstall
> cd widgets && npm install
npm WARN using --force Recommended protections disabled.
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /__w/angular-frontend/angular-frontend/widgets/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/__w/angular-frontend/angular-frontend/widgets/node_modules'
npm ERR! [Error: EACCES: permission denied, mkdir '/__w/angular-frontend/angular-frontend/widgets/node_modules'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/__w/angular-frontend/angular-frontend/widgets/node_modules'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /github/home/.npm/_logs/2023-01-12T10_19_14_334Z-debug.log
npm ERR! code 243
npm ERR! path /__w/angular-frontend/angular-frontend
npm ERR! command failed
npm ERR! command sh -c cd widgets && npm install
npm ERR! A complete log of this run can be found in:
npm ERR! /github/home/.npm/_logs/2023-01-12T10_19_14_398Z-debug.log
Error: Process completed with exit code 243.
Install Dependencies step runs npm install and in my package.json I have a postinstall script
{
"scripts": {
"postinstall": "cd widgets && npm install"
}
}
Seems the permissions error comes from the container image houzy/frontend-builder:16.13.1, cause removing the container part from workflow makes the pipeline work. I would like to understand what I should set in the container part from the worflow or in the Dockerfile for creating this image to make it work.
Here is the Dockerfile to create the image:
# Dockerfile used for replacing bitbucket pipeline start image
FROM node:16.13.0
RUN apt-get update; apt-get install -y gettext-base;
RUN echo 'deb http://dl.google.com/linux/chrome/deb/ stable main' > /etc/apt/sources.list.d/chrome.list
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN set -x && apt-get update && apt-get install -y xvfb google-chrome-stable
RUN wget -q -O /usr/bin/xvfb-chrome https://bitbucket.org/atlassian/docker-node-chrome-firefox/raw/ff180e2f16ea8639d4ca4a3abb0017ee23c2836c/scripts/xvfb-chrome
RUN ln -sf /usr/bin/xvfb-chrome /usr/bin/google-chrome
RUN chmod 755 /usr/bin/google-chrome
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install
RUN curl -O https://bootstrap.pypa.io/get-pip.py && python3 get-pip.py --user && ~/.local/bin/pip install --upgrade awsebcli
As a side note I use the same image in bitbucket-pipelines and there it works so maybe just the start container command is different on github-actions ?

Terminal 'ionic start' gives npm ERR

I am trying to start my first ionic project based on VUE, following the steps on https://ionicframework.com/docs/intro/cli
I reinstalling nodejs, tried uninstalling ionic > npm cache clear --force > reinstall, as well as launching Visual Studio Code in admin mode. Keep getting same error below. I am out of options, any advice?
? Starter template: blank
√ Preparing directory .\myapp in 1.41ms
√ Downloading and extracting blank starter in 320.71ms
> ionic integrations enable capacitor --quiet -- myapp io.ionic.starter
> npm.cmd i --save -E #capacitor/core#latest
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN ERESOLVE overriding peer dependency
npm ERR! code ECONNRESET
npm ERR! network aborted
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User\AppData\Local\npm-cache\_logs\2022-07-18T02_58_39_592Z-debug-0.log
[ERROR] An error occurred while running subprocess npm.
npm.cmd i --save -E #capacitor/core#latest exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
Installing dependencies may take several minutes.
──────────────────────────────────────────────────────────────────────────────
Ionic Advisory, tailored solutions and expert services by Ionic
Go to market faster
Real-time troubleshooting and guidance
Custom training, best practices, code and architecture reviews
Customized strategies for every phase of the development lifecycle
Learn more: https://ion.link/advisory
──────────────────────────────────────────────────────────────────────────────
> npm.cmd i
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN ERESOLVE overriding peer dependency
npm ERR! code ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC
npm ERR! 13168:error:1408F119:SSL routines:ssl3_get_record:decryption failed or bad record mac:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:677:
npm ERR!
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User\AppData\Local\npm-cache\_logs\2022-07-18T02_59_54_033Z-debug-0.log
[ERROR] An error occurred while running subprocess npm.
npm.cmd i exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
I've had the same issue myself but not had much chance to do any digging in to why it's doing it yet but could be a breaking change in a newer version of Angular which the Ionic team haven't picked up on.
In the meantime (assuming you're using Angular), use:
ng serve and access it at http://localhost:4200.

Build Failed in ionic 2 for IOS

Running ionic cordova build ios will result in the following error:
Preparing Firebase on iOS
IOS project Code Sign Entitlements now set to: LifeBuddy/Resources/LifeBuddy.entitlements
Entitlements file is in reference section.
Error: ios-deploy was not found. Please download, build and install version 1.9.2 or greater from https://github.com/phonegap/ios-deploy into your path, or do 'npm install -g ios-deploy'
[ERROR] An error occurred while running cordova build ios (exit code 1).
When running the suggested command npm install -g ios-deploy I receive this error:
The following build commands failed:
Check dependencies
Write auxiliary files
(2 failures)
npm ERR! code ELIFECYCLE
npm ERR! errno 65
npm ERR! ios-deploy#1.9.3 preinstall: `./src/scripts/check_reqs.js && xcodebuild`
npm ERR! Exit status 65
npm ERR!
npm ERR! Failed at the ios-deploy#1.9.3 preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/dev-13/.npm/_logs/2018-07-31T08_07_03_860Z-debug.log
Try this,
sudo npm install -g ios-deploy --unsafe-perm=true

Error: package reason-react not found or built

After running:
bsb -init my-react-login-app -theme react
Then, I ran the following to, as I understand, build the project:
$npm run build
But, I got the following error output:
> my-react-login-app#0.1.0 build /Users/kevinmeredith/Workspace/my-react-login-app
> bsb -make-world
Package not found: resolving package reason-react in /
File "bsconfig.json", line 1
Error: package reason-react not found or built , if it is not built
Please run 'bsb -make-world', otherwise please install it
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! my-react-login-app#0.1.0 build: `bsb -make-world`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the my-react-login-app#0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/kevinmeredith/.npm/_logs/2018-06-24T01_36_13_899Z-debug.log
How can I resolve this issue?
See the readme; that template needs you to install reason-react through npm install or yarn add. After that it should work. We don't check in the entire reason-react dependency chain in the template.

build prod failed: spawn EACCES with ionic2

I build an hybrid app using Ionic 2.
I got a windows pc and using mac virtual box for Xcode.
I can run the app on browser and android just fine in my windows.
problem is when I'm moving to mac I'm doing the same things on node JS and I get errors.
I used those lines in the terminal
ionic start/run/emulate/build Vme2
sudo ionic start/run/emulate/build Vme2
none works
this is the error I get
> ionic-hello-world# build /Users/amitaimazliah/Desktop/Vme2
> ionic-app-scripts build
[08:38:07] ionic-app-scripts 0.0.38
[08:38:07] build prod started ...
[08:38:07] clean started ...
[08:38:07] clean finished in 3 ms
[08:38:07] copy started ...
[08:38:07] ngc started ...
[08:38:07] copy finished in 262 ms
[08:38:07] build prod failed: spawn EACCES
[08:38:07] ionic-app-script task: "build"
[08:38:07] Error: spawn EACCES
npm ERR! Darwin 14.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
npm ERR! node v6.9.1
npm ERR! npm v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! ionic-hello-world# build: `ionic-app-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ionic-hello-world# build script 'ionic-app-scripts build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ionic-hello-world package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ionic-app-scripts build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs ionic-hello-world
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls ionic-hello-world
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/amitaimazliah/Desktop/Vme2/npm-debug.log
Caught exception:
undefined
Mind letting us know? https://github.com/driftyco/ionic-cli/issues
[08:38:07] lint started ...
[08:38:08] tslint: src/pages/home/home.ts, line: 57
Unused method: 'setNewPhotos'
L57: private setNewPhotos()
[08:38:08] lint finished in 1.27 s
(node:2376) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: channel closed
any ideas what am I doing wrong?
thanks
You have problem when build app.Can you try use this command '
ionic hooks add
Cheer !