0
votes

Problem: For some reason our Private build agent throws the following error:

"'webpack' is not recognized as an internal or external command" when we try to invoke npm run build:prod

What I've tried:

  • I tried installing webpack globally using: npm install --global webpack

  • I tried adding webpack to the path variable

  • I tried running the command 'npm run build:prod' directly on the build servrer (agent) - it works fine

Additional info:

  • Our AzureDevops build agents run as the NetworkService user

  • In AzureDevOps, I added a build task "npm" install and an additional step which runs "npm run build:prod"

This is the complete error message:

[command]C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" --version"
5.6.0
[command]C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" config list"
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/5.6.0 node/v8.9.4 win32 x64"

; environment configs
userconfig = "E:\\vsts-agent\\aztc-agent-1\\_work\\28\\npm\\3704.npmrc"

; builtin config undefined
prefix = "C:\\Windows\\ServiceProfiles\\NetworkService\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; cwd = E:\vsts-agent\aztc-agent-1\_work\28\s\Src\Project\Template\Code
; HOME = C:\Windows\ServiceProfiles\NetworkService
; "npm config ls -l" to show all defaults.

[command]C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" run build:prod"

> [name]@0.0.1 build:prod E:\vsts-agent\aztc-agent-1\_work\28\s\Src\Project\Template\Code
> webpack --config webpack.config.prod.js --progress
'webpack' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
1
Does Webpack is in package.json as dev dependency but Build Agent NODE_ENV var set to "production"?Romain V...

1 Answers

0
votes

What worked for me in the end was:

  1. Add Npm task of type "install"
  2. Add path to where package.json file is located
  3. Add Npm task of type "custom" with working folder pointing to same folder as in step 2. and with "Command and arguments" field set to "run build:prod"