28

How to Add Parameters for 'npm install' in Azure DevOps

 1 year ago
source link: https://edi.wang/post/2022/7/7/how-to-add-parameters-for-npm-install-in-azure-devops
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to Add Parameters for 'npm install' in Azure DevOps

Original

Edi Wang

Thursday, July 7, 2022 China Standard Time

2 Reads


Recently my Azure DevOps build pipeline failed because Azure is using npm 8.x, which will have issue for angular projects when running `npm install`.  This is a known issue which can be solved by using `--legacy-peer-deps` or `--force` for the `npm install` command. However, Azure DevOps's npm task is not taking parameters by default. Let's see how we can use these parameters in Azure DevOps.

Old YAML file


  - task: Npm@1
    displayName: 'npm install'
    inputs:
      workingDir: '$(System.DefaultWorkingDirectory)/src/Web/work996'
      command: 'install'

It produces error:

img-d12a29c7-4d19-470e-b952-818b83fdb44f.png

Custom Command


To solve this issue. We need to use custom command for the npm task.

  - task: Npm@1
    displayName: 'npm install with legacy-peer-deps'
    inputs:
      workingDir: '$(System.DefaultWorkingDirectory)/src/Web/work996'
      command: 'custom'
      customCommand: 'install --legacy-peer-deps'

Now the build will work fine.

img-da7b709d-525c-4acf-80fa-3f03d0b9f16c.png

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License



About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK