11

I am getting npm warnings as errors during build using build definition. enter image description here

I then added following property in MSBuild Arguments in Build Definition:

/p:TreatWarningsAsErrors=False

but it is not working yet.

I also cross-checked by right-clicking each project and none of them has the option "Treat Warnings as Errors" checked.

I am calling npm install command from post-build script.

I also restarted build controller and build agent after changes that I tried but no success.

Any help in this direction is appreciated.

CodeZila
  • 919
  • 2
  • 14
  • 31

5 Answers5

8

It's possible to use the loglevel option so that warnings simply don't appear at all. This avoids the problem of having warnings show in standard error thus halting builds or writing errors for warnings.

I typically use npm install --loglevel=error --no-update-notifier. I've noticed that update-checks also can interrupt the build process for npm.

Martin
  • 619
  • 5
  • 13
7

MSBuild arguments won't help you here... the post-build script runs after MSBuild has finished executing.

The problem is that npm is writing its warnings to the stderr stream, which TFS detects and reports as a an error. You can suppress this by redirecting the error stream to stdout like so:

npm install 2>&1

However, this will suppress errors as well as warnings, which may or may not be acceptable in your case. In our case, we call npm install from a PowerShell script during the pre-build script. We redirect the output, but then we also scan the output looking for the string ERR! like so:

& npm install *>&1 | ForEach-Object {
    $obj = $_
    if ( $obj -is [System.Management.Automation.ErrorRecord] ) {
        $s = $obj.Exception.Message
    }
    else {
        $s = $obj.ToString()
    }
    if ( $s.Contains('ERR!') ) {
        Write-Error $s
    }
    else {
        Write-Output $s
    }
}
$LASTEXITCODE = 0

Note that we also set $LASTEXITCODE to zero so that PowerShell doesn't pass the exit code from npm back to TFS.

JamesQMurphy
  • 4,214
  • 1
  • 36
  • 41
  • Is this still working for you? I can't seem to get this working. – Michael Armstrong Apr 18 '18 at 20:59
  • 1
    @MichaelArmstrong Since then, we have upgraded to TFS 2017 and are now using the new build agents, so I don't know. The npm tasks there work great. If it is at all possible for you, I highly recommend doing the same. – JamesQMurphy May 03 '18 at 12:54
  • Any suggestion when I have the problem on one agent but not on the other? Both VM's in Azure, the one with the problem is the latest windows 10 server VS2019 community edition template. – CularBytes Aug 18 '20 at 07:07
6

Within the CI Server, This is a very common issue that pipeline gets failed whenever we run 'npm build'

We receive some warnings and the CI server considers them as errors and the pipeline gets terminated.

To remove this error just add environment variables within the pipeline as mentioned below:

env:
  CI: false
deep bajaj
  • 61
  • 1
  • 1
1

You can silence npm during the install process with the --silent argument:

npm install --silent

You don't need any msbuild argument this way.

Matthieu
  • 4,605
  • 4
  • 40
  • 60
0

Please try to use the correct syntax instead of yours

/p:TreatWarningsAsErrors="false"
PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • It doesn't work with XAML build definition in TFS2015.3. Warning from NPM still get treated as errors. – Matthieu Feb 14 '17 at 02:50