tfs 2017 on site npm build - node.js

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.

Related

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

NPM versions during development and production

From what I have read it is a good idea to use the same version of Node.js throughout the development and production phases of an app.
Is this also true of NPM? It looks as if NVM is keeping specific versions of NPM together with specific versions of Node.js inside the .nvm directory. However, although I can see from the NVM documentation how to make sure you run an app with a particular version of Node.js, I can not see how to make sure that a particular version of NPM is used for a particular app. For example if I run the command npm install package from the root directory of an app I think it will use the default version of NPM not the specific version associated with the Node.js version specified in the .nvmrc file of the app.
Do I need to be consistent in the version of NPM I use during app development and production? If the answer is yes how do I achieve that?
When we start a Project using Nodejs a file named package.json is created automatically and it keeps track of all the dependencies in the ongoing Project. So you do not need to worry about the versions, you just have to start the project and all the dependencies will be taken care of.
Suppose you need to share your codes(like Git) then you just need to share your codes and package.json file that will do the trick.

VSTS with gulp v.4.0.0

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.

How to get jenkins to use current npm version?

A project I am on has a Jenkins server to which I don't have remote access.
The server admin has installed npm 5.8 using npm install -g npm.
Executing npm -v reports a version of 5.8.
However, during the Jenkins build process, npm -v reports a version of 5.6 which is the version that shipped with the installed version of NodeJS.
Can someone assist me in what I should be asking the admin to change?
The admin should be able to install the Jenkins NodeJS Plugin which allows you to handle several different installations (in different versions) of NodeJS. This way you can address the version of NodeJS & npm you want to use from the Job configuration, as the correct folder is temporarily added to the PATH variable.
There is a walkthrough guide on the wiki page of the plugin.
Following steps will help you:
If it is windows machine, you better to restart the node after you install anything. Then only Jenkins can get the updated environment variables.
Verify the Environment variable pointed to correct version folder.
If you know the updated installed path then you can create local environment variable at job level using following command.
env.NODE_HOME =
"C:\Windows\system32\config\systemprofile\AppData\Roaming\npm"

How to use latest npm on Azure Mobile Service deployment

The Azure Mobile Service image that I am using currently is locked down to npm version 1.2.30. There are latest npm version installed on the image(under ...\Program Files(x86)\npm). But npm is locked down to the version 1.2.30 due to the reason that it was installed with node.js(under ...\Program Files(x86)\nodejs) AND the path always looks under \nodejs\ folder first and uses it.
This is causing me problem in using some npm packages (including googleapis) on deployment. The errors appear while installing googleapis are bugs in older version of npm and are resolved in latest.
The simplest solution is to delete the 'npm' file and 'npm.cmd' file under ...\Program Files(x86)\nodejs\ folder so that the npm is read from ..\Program Files(x86)\npm\ folder. But i get access denied errors while trying to access these files. I am accessing the mobile service image through Kudu interface.
Is there are work-around for this?
For upgrading npm, you can follow the instructions from David Ebbo on this forum post: https://social.msdn.microsoft.com/Forums/azure/en-US/068ef026-f80d-4bf8-9f40-5d1af33a1024/git-deployment-fails-with-npm-error-when-resolving-a-package-version-containing-a-?forum=windowsazurewebsitespreview

Resources