Webpack代理的Azure管道失败

时间:2020-09-11 13:06:05

标签: webpack azure-devops

Webpack的Azure管道运行失败,并在运行时出现以下错误。

  [error]webpack failed
  [error]Error: Command failed: node  "D:\project\node_modules\webpack\bin\webpack.js" --json --config 
  ../project/webpack.config.js
  internal/modules/cjs/loader.js:960
   throw err;
  Error: Cannot find module 'D:\project\node_modules\webpack\bin\webpack.js'
      at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
      at Function.Module._load (internal/modules/cjs/loader.js:840:27)
      at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
      at internal/main/run_main_module.js:18:47 {
     code: 'MODULE_NOT_FOUND',
   requireStack:[]
  }

正如我检查过的那样,webpack.js存在于特定位置,但是管道仍然显示此错误。

PFB WebpackAgent Configuration 
 Task Version: 4.
 DisplayName : Webpack
 webpack cli arguments : --config ../project/webpack.config.js
 treat error as: errors
 treat warning as : warnings
 working folder: <folder_Name>
 webpack cli location : '/node_modules/webpack/bin/webpack.js'
 stats.js location : '/project/node_modules/webpack/lib/Stats.js'

因此,请为该问题提供任何解决方案

1 个答案:

答案 0 :(得分:0)

看来您是在本地托管代理上构建管道。首先,您需要检查本地托管代理计算机上的文件夹D:\project\node_modules中是否存在webpack和webpack-cli。

如果您为Webpack任务指定了working folder字段。管道将在指定的工作文件夹中查找webpack。您可以添加脚本任务以在指定的工作文件夹中安装webpack和webpack-cli。

对于以下示例: 我已将Webpack任务配置为以下屏幕截图。我将D:\test指定为working folder

enter image description here

在执行Webpack任务之前,我将Powershell任务添加到文件夹webpack中已安装的webpack-cliD:\test包中

enter image description here

如果您没有为Webpack任务指定working folder字段。管道将在默认工作文件夹($(system.defaultworkingdirectory),例如C:\agent\_work\1\s\node_modules)中查找webpack。

在执行Webpack任务之前,您仍然需要安装webpackwebpack-cli软件包。

npm install webpack webpack-cli --save-dev

以上将在$ {system.defaultworkingdirectory)\ node_modules(例如webpack)中下载webpack-cliC:\agent\_work\1\s\node_modules