We are using TFS Build Tasks and one of the tasks runs npm install
. This is NOT through a batch or powershell file.
It runs successfully but it looks like it completes and then hangs for about 3 to 4 minutes. I know this because the task summary says it successfully completed but it doesn't start the next task for 3 to 4 minutes.
Originally when I added the task, I don't think it would hang like this. I'm not sure what changed.
I tried using npm set progress=false
, recommended from this forum and explained in this article. I haven't added npm-cache
because it doesn't seem to be relevant; remember, the build task completes successfully and then hangs.
What could cause the npm task to hang after completing?
According to your description, it is make sense. NPM install is just wasting time because it takes 3-4 minutes to determine the packages are already installed.
Fist try to run you npm from the console to see the performance on TFS is normal or not. If all of your NPM tasks are taking long time, one possibility is related to nodejs version.
For instance, you are using a latest version such as nodejs (8.2.0) installed on the build agent. Then downgrade to the latest LTS (long term support) version (6.11.1) may resolve the issue for you. Details please have a look at this blog.
Another way is using npm-cache as an alternative way since you use on-premise build agents for build.
It is useful for build processes that run [npm|bower|composer|jspm] install every time as part of their build process. Since dependencies don't change often, this often means slower build times. npm-cache helps alleviate this problem by caching previously installed dependencies on the build machine. npm-cache can be a drop-in replacement for any build script that runs [npm|bower|composer|jspm] install.
How it Works
When you run npm-cache install [npm|bower|jspm|composer], it first looks for package.json, bower.json, or composer.json in the current working directory depending on which dependency manager is requested. It then calculates the MD5 hash of the configuration file and looks for a filed named .tar.gz in the cache directory ($HOME/.package_cache by default). If the file does not exist, npm-cache uses the system's installed dependency manager to install the dependencies. Once the dependencies are installed, npm-cache tars the newly downloaded dependencies and stores them in the cache directory. The next time npm-cache runs and sees the same config file, it will find the tarball in the cache directory and untar the dependencies in the current working directory.
A sample for your reference: Speed up your npm dependent CI build
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With