VSTS with gulp v.4.0.0 - node.js

I'm having the gulp version of one of my projects. Previously we were using version 3.9.1 and we were hestitative updating.
After updating i have fixed all local issues and tested the project on a different computer (after updating the installed gulp there as well) it works fine.
Our automatic deployment however won't agree with me.
After a check-in our VSTS does the following steps
install npm
execute command
build project
However, this produces the following error.
Working directory changed to D:\a\1\s\MVC
Using gulpfile D:\a\1\s\MVC\gulpfile.js
C:\NPM\Modules\node_modules\gulp\bin\gulp.js:129
gulpInst.start.apply(gulpInst, toRun);
^
TypeError: Cannot read property 'apply' of undefined
at C:\NPM\Modules\node_modules\gulp\bin\gulp.js:129:20
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
This error seems to be caused by an out of date cli version of gulp. But i can't figure out how to update this using VSTS.
Concrete problem
How do i update gulp cli in VSTS
What have i done already?
After some checking i saw the npm version installed was very old (3.10.8). I've dragged in a nodejs installer which updates to the latest version and gives me the latest version of nodejs, and a much newer version of npm (5.6.0) which i've used at on-hands computers to update the cli version. however i can't figure out how to do this in VSTS.

It seems that you are using Hosted Agent which the installed npm version is 3.10.8. You just need to add a Node Tool Installer task in your build definition and set it to use "8.x" version. It will install the 8.x version which include npm 5.6.0.
npm version before Node Tool Installer task:
npm version after Node Tool Installer task:

Try to install/update gulp-cli through NPM task:
BTW, the package in package.json will be installed on current project/folder instead of global, you need to call gulp command through npm command (scripts property of package.json) to use package in current project/folder or specify the path directly (e.g. ./node_modules/gulp/bin/gulp)

The solution that I found worked for me was to change the Pipeline from Hosted to Hosted VS2017.
I had completed a PR that upgraded the Gulp to 4.0, and the PR build completed but the CI build failed with strange results. After a lot of searching, I narrowed it down to the PR build already being set to Hosted VS2017 (it was building C# projects too that required them) and the CI build was only doing the Gulp build and was set to Hosted.

Related

Error - React Native CI - Azure DevOps - Gulp

I'm trying to use Azure DevOps for a React Native app. I'm using gulp to generate an Android App which already has the signing-configs ready and I don't have any problem with it.
My error in Azure DevOps is:
And my .yml file has the following tasks:
Install Node 8.16.0
npm install
Using gulp task to generate the APK
My CI fails at the 3rd step. I googled so many kinds of stuff, all say to check the Node version which should be greater than 6 as you see I'm already on 8.
So far I tried the below three steps and nothing worked for me.
Installing #react-native-community/cli as a dev dependency or
globally.
Installing gulp globally or as a dev dependency
Generating package.json without lock file and ignoring optional dependencies.
Any idea on how to resolve this?
I was able to solve my issue for now by upgrading to the latest vmImage.
Changing this
vmImage: 'macOS-latest' #This is macOS Mojave
to
vmImage: 'macOS-10.15' #This is macOS Catalina
solved my problem

Azure DevOps self hosted agent reports wrong version for NPM

We have updated Node to version 10.16.3 and NPM to version 6.11.3 (all the latest at this time) on our Windows based self hosted agent.
However, in a job run logs, we see that the agent reports version 6.9.0 for NPM, which is the default version for Node 10.16.3 installation.
Inside the VM where the hosted agent is, if I run 'npm' in the CMD, I get the latest version for NPM. Also, if I run the same command that the agent is running to get the version, I still get the correct version for NPM:
What could be wrong here?
The reason we want the latest version of NPM is because our builds run faster with it.
Thank you!
We have had a very amateur approach to this problem. When we are logging in through RDP, we are using the user 'agent' and all installations are scoped to that user. However, the agent is using the NetworkService user, which has its own scope for NPM and Node.
The fix was basically to add step in our build pipeline to check for latest version of NPM and install it in case it is not installed.
Yeah, I got caught out by this too. Because it runs under the NetworkService account, it can't read the global folder, so has it's own little copy/cache at
C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\npm
My easiest way to get back up and running, was to just manually upgrade the npm at that location using the following command:
npm install --prefix C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\npm npm

tfs 2017 on site npm build

I am trying to get a npm build of SPA application using the npm build task. I need the task to use the latest Nodejs and NPM, how can I update the binaries of the task? I have installed the Nodejs on the TFS Build machine but the npm task is not using the latest version, it seems there is another version fixed to tfs in some location
Normally you just need to update the Nodejs to the latest version, then the NPM task will call the latest version of Nodejs accordingly.
So, please check if you have installed multiple versions of Nodejs in different directory, If it is, just remove the old one.
And go to your pool settings page: http://server:8080/tfs/_admin/_AgentPool and select your agent, verify that if the Node.exe and NPM are identified as a system capability with the correct path set. If the latest version not existing there, just try to restart the agent service to sync it, if still not be identified, you can try to add it manually. Then try it again.

Webpack Binding Issue

Hey guys for some reason I keep getting this error when building with sass-loader
Module build failed: Error: Missing binding C:\TFS_Local\DPOnGit\node_modules\node-sass\vendor\win32-ia32-11\binding.node
Node Sass could not find a binding for your current environment: Windows 32-bit with Node 0.10.x
Found bindings for the following environments:
- Windows 64-bit with Node.js 5.x
This usually happens because your environment has changed since running npm install.
Run npm rebuild node-sass to build the binding for your current environment.
Very frustrating as this config has worked on the same machine before without issues.
I had the same problem, rebuilding as suggested by the error message didn't work for me, but running
npm install --save sass-loader
did.

NPM - Can't install socket.IO

I am trying to install socket.io on windows with npm for use on a nodeJS server.
First, when I typed "npm install socket.IO" i had an error in the log saying something about python and node-gyp. I installed python 2.7.3 and set the environment variables.
Now I got a new error, which has something to do with visual studio (what the hell does VS have to do with npm ? Is it about the compiler? ).
The error is the same as here npm install for some packages (sqlite3, socket.io) fail with error MSB8020 on Windows 7
But when I use the option in the answer instead of the error it tells me something about a possible data loss (c4267) but doesn't log any error.
Then when I start my app, it tells me cannot find module socket.io still
What could this come from ?
Oh and also when i do npm config get root it tells me "undefined" could it have anything to do with it ?
Should I install the modules globally or locally ?
At least one of the packages in Socket.IO's dependency tree is a C/C++ addons which needs to be compiled on your system as it's installed. And, since it's a dependency, if it doesn't succeed in installing, neither will Socket.IO.
To enable cross-system compilation, Node.js uses node-gyp as its build system. You'll need to have it installed as a global package:
npm install -g node-gyp
As well as have its dependencies installed. Abridged version:
Python 2
C/C++ Compiler / Build Tools
For Windows, Microsoft Visual Studio 2013 (C++ or Windows Desktop) (Express edition)
For 64-bit, may need Windows 7 64-bit SDK
Then, you should be able to install Socket.IO as a local package so you can require it:
npm install socket.io
I had a similar problem on Mac.
What resolved my problem is installing a slightly older version of Socket.io.
I did:
npm install socket.io#"~0.8.1"
which would install the latest version between 0.8.0 to 0.8.9, but not 0.9.0 or above.
Socket.io then installed perfectly.
Make sure you have all the required software to run node-gyp:
https://github.com/TooTallNate/node-gyp
You can configure version of Visual Studio used by gyp via an environment variable so you can avoid having to set the --msvs_version=2012 property.
Examples:
set GYP_MSVS_VERSION=2012 for Visual Studio 2012
set GYP_MSVS_VERSION=2013e (the 'e' stands for 'express edition')
For the full list see
- https://github.com/joyent/node/blob/v0.10.29/tools/gyp/pylib/gyp/MSVSVersion.py#L209-294
This is still painful for Windows users of NodeJS as it assumes you have a copy of Visual Studio installed and many end users will never have this. So I'm lobbying Joyent to the encourage them to include web sockets as part of CORE node and also to possible ship a GNU gcc compiler as part of NodeJS install so we can permanently fix this problem.
Feel free to add your vote at:
https://github.com/joyent/node/issues/8005#issuecomment-50545326
The problem causing the compile failure is that the ws module installed by the engine.io module required by socket.io pulls in a backlevel version of nan. See https://github.com/BrowserSync/grunt-browser-sync/issues/95 for details. To work around the problem after the build failure:
cd to node_modules/socket.io/node_modules/engine.io/node_modules/ws
edit package.json to change the release of nan from 1.4.x to 1.6.0
issue command node-gyp rebuild
You should now be able to use socket.io
Another approach is to use Docker for Windows and spin up a NodeJS environment. While developing you can mount your Node code as a Docker volume and so continue to update your code from Windows but execute it and install it's dependencies inside a Linux VM. When you deploy you might prefer to use a Dockerfile that COPY's your Node code into your Docker image and so bakes it into the release image you deploy.
This approach might be required if you don't want to risk changing the socket.io version of your code or its dependencies.
It also may be a valuable solution if you planned to deploy to a corporate Intranet or public/private Cloud.
Docker can also be very handy for testing deployment under different versions of Node without disturbing the development environment of your Windows computer (e.g. for testing a NodeJS lib).
Official NodeJS Docker images
An explanation of how to use these images
this problem makes me very troubled..
I tried many solutions.
I installed .NET Framework 2.0 SDK.
I installed Python 2.7.x
I installed VS 2012 Express
I set some paths
I executed npm install xxx with the argument --msvs_version=2010(or 2012/2013..)...
But all failed.
finally, I uninstalled Python & .NET Framework 2.0 SDK & VS 2012, clear those paths,enable Windows Update, install all essential updates, restart my computer
then execute commands below:
npm install node-gyp -g
npm install socket.io -g
npm install browser-sync -g
there is no errors in installation logs.
Note : this solution may not work for you, but for me

Resources