By default, you have 1 node.js and NPM version installed on your machine. However, if you have to maintain applications written in multiple Angular and/or Typescript versions, this can become a problem. Older Angular/Typescript applications are not compatible with the latest node.js version and can no longer be compiled.
In Linux, this has been solved by the introduction of nvm , the node version manager. With it, it is possible to quickly install(and uninstall) different node.js versions and easily switch between them via the command line.
NVM-Windows
With nvm-windows, an alternative is also available for Windows. You can easily install nvm-windows on your local machine via the installer available here: https://github.com/coreybutler/nvm-windows/releases .
Using nvm-windows is very simple:
- Install a node.js version:
nvm install <version>
- Listing the installed versions:
nvm list
- Switching between versions:
nvm use <version>
Note: Global packages(if used) must be installed per node.js version.
Using NVM-Windows on your build server
NVM-Windows is not only useful on your local dev machine but can be a big help on your build server as well. Install nvm-windows on your build server after which you can invoke it in your YAML templates:
# ASP.NET Core (.NET Framework) | |
# Build and test ASP.NET Core projects targeting the full .NET Framework. | |
# Add steps that publish symbols, save build artifacts, and more: | |
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core | |
trigger: | |
- master | |
pool: | |
name: 'default' | |
variables: | |
solution: '**/example/*.sln' | |
buildPlatform: 'Any CPU' | |
buildConfiguration: 'Development' | |
artifactName: 'Example' | |
steps: | |
- task: PowerShell@2 | |
displayName: 'nvm use 16.14.0' | |
inputs: | |
targetType: 'inline' | |
script: | | |
nvm install 16.14.0; | |
nvm use 16.14.0; |
Keep in mind that changing the node.js version is a global change that impacts all build agents.
So also remember to always reset the node.js version to the latest version in your build pipeline.