0

I want to build npm packages via Azure DevOps. My build pipeline fails because peer dependencies are not installed. Is there a way to install the peer dependencies from the package.json?

Below is my sample azure-pipelines.yml file for building and publishing my npm package.

pool:
  name: Azure Pipelines
  demands: npm
  vmImage: 'ubuntu-latest'

steps:
- task: Npm@1
  displayName: 'npm install'
  inputs:
    verbose: false

- task: Npm@1
  displayName: 'npm install project'
  inputs:
    workingDir: 'projects/my-project'
    verbose: false

- task: Npm@1
  displayName: 'ng build'
  inputs:
    command: custom
    verbose: false
    customCommand: 'run ng build -- --prod'

- task: Npm@1
  displayName: 'npm publish'
  inputs:
    command: publish
    workingDir: 'dist/my-project'
    verbose: false
    publishEndpoint: NPM
  condition: contains(variables['Build.SourceBranch'], 'master')

Bonus question: How do I apply a tag when publishing?

Joel'-'
  • 652
  • 1
  • 5
  • 17

1 Answers1

0

For this issue ,first, you need to make sure that the Working folder specified in the npm install task contains target package.json.

Secondly, do all the dependent packages you need to use exist in the public feed? If not, you need to use packages from your Azure Artifacts feed.

enter image description here

In addition, you need to make sure that the dependent packages are specified in your package.json. If everything is ok, can you run successfully locally?

Update:

The automatic install of peer dependencies was explicitly removed with npm 3.

Here is the case you can refer to .

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25
  • All normal packages are installed just fine. However, the _peer dependencies_ are not installed with `npm install` – Joel'-' Apr 08 '20 at 12:29
  • Can it run successfully locally? Can you share a detailed log about npm install task? – Hugh Lin Apr 09 '20 at 09:19
  • Locally I do `npm install peer-dependency-name`. Then the build works fine. In azure devops, I solved it by adding a shell-exec task, which also does `npm install peer-dependency-name` But I would like this to happen automatically based on the package.json, so that if someone adjusts the package.json, the pipeline wont break – Joel'-' Apr 09 '20 at 10:43
  • 1
    Since peer dependencies also cannot be automatically installed locally, you need to run `npm install peer-dependency-name` additionally , so I think the problem should be in package.json, please check it. – Hugh Lin Apr 10 '20 at 09:52
  • The package.json is fine. If I install the packages through a shell function (e.g. bash), in the pipeline, it will build the code fine. However, I am looking for a way to have Azure Pipelines detect which peer dependencies there are, and install them automatically – Joel'-' Apr 12 '20 at 19:02
  • The automatic install of peer dependencies was explicitly removed with npm 3. Please refer to this [case](https://stackoverflow.com/questions/35207380/how-to-install-npm-peer-dependencies-automatically). – Hugh Lin Apr 14 '20 at 10:18
  • @Joel'-' Did you ever find a solution for installing the peer deps automatically when running the build on azure? – Nico Mar 30 '23 at 17:18
  • I'm doing them manually in the pipeline – Joel'-' Apr 06 '23 at 11:24