Disable Npm warnings as Errors: build definition tfs
Asked Answered
J

5

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.

Jacoby answered 21/1, 2016 at 7:42 Comment(0)
T
12

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.

Thickskinned answered 7/8, 2018 at 8:14 Comment(1)
@Codezila this should be the accepted answerSapers
N
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.

Namtar answered 19/3, 2017 at 20:16 Comment(3)
Is this still working for you? I can't seem to get this working.Alvita
@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.Namtar
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.Shamikashamma
K
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
Kidron answered 4/3, 2021 at 6:48 Comment(0)
M
1

Please try to use the correct syntax instead of yours

/p:TreatWarningsAsErrors="false"
Myotonia answered 22/1, 2016 at 7:44 Comment(1)
It doesn't work with XAML build definition in TFS2015.3. Warning from NPM still get treated as errors.Swing
S
0

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

npm install --silent

You don't need any msbuild argument this way.

Swing answered 14/2, 2017 at 2:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.