问题描述
我的 azure 管道 yaml 中有这一步:
- task: webpack@4
displayName: webpack
inputs:
webpackCliArguments: '--config webpack.$(buildConfiguration).config.js'
workingFolder: $(projects.workingFolders.webApi)
它一直运行良好,通常在管道中的这一步在大约 8 分钟左右完成
最近,我向 [contenthash]
添加了这些 webpack.config.js
更改,以防止用户在部署更改后必须硬刷新:
const devMode = process.env.NODE_ENV === 'development'; plugins: [
new CleanWebpackPlugin(pathsToClean,cleanoptions),new MiniCssExtractPlugin({
filename: devMode ? "[name].bundle.css" : "[name].[contenthash].bundle.css"
})
],output: {
.... ....
filename: devMode ? "[name].bundle.js" : "[name].[contenthash].bundle.js"
},
现在突然管道将挂在 webpack
步骤,并在一个小时超时后取消整个运行。 这种情况间歇性发生,似乎平均每 2 次运行就会发生一次
##[错误]操作被取消。
我没有证据证明我的改变是造成这种情况的原因,但时间非常巧合。
有谁知道在 webpack 输出的文件名中使用 [contenthash]
是否会导致这样的挂起?或者,有谁知道我如何调试这个问题?
例如,如何让 webpack 将任何问题记录到 azure 管道窗口? console.log 似乎不起作用。
设置 system.debug=true
后,我现在可以在日志中看到以下消息
executing the command: node --inspect "E:\Builds\RemoteAgent1\_work\613\s\Project\node_modules\webpack\bin\webpack.js" --json --config webpack.Release.config.js --display verbose
##[debug]Re-evaluate condition on job cancellation for step: 'webpack'.
##[error]The operation was canceled.
##[debug]System.OperationCanceledException: The operation was canceled.
at System.Threading.CancellationToken.ThrowOperationCanceledException()
at Microsoft.VisualStudio.Services.Agent.Util.ProcessInvoker.ExecuteAsync(String workingDirectory,String fileName,String arguments,IDictionary`2 environment,Boolean requireExitCodeZero,Encoding outputEncoding,Boolean killProcessOnCancel,InputQueue`1 redirectStandardIn,Boolean inheritConsoleHandler,Boolean keepStandardInopen,Boolean highPriorityProcess,CancellationToken cancellationToken)
at Microsoft.VisualStudio.Services.Agent.ProcessInvokerWrapper.ExecuteAsync(String workingDirectory,CancellationToken cancellationToken)
at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.DefaultStepHost.ExecuteAsync(String workingDirectory,CancellationToken cancellationToken)
at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.NodeHandler.RunAsync()
at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.RunAsync()
at Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.RunStepAsync(IStep step,CancellationToken jobCancellationToken)
解决方法
仍然不确定这里的问题是什么,但我们设法通过从 webpack 配置 thread-lodaer
中删除 module.rules
来解决它:
...
{
test: /\.(sa|sc|c)ss$/,use: [MiniCssExtractPlugin.loader,'thread-loader',// remove this line
{ loader: 'css-loader',options: { sourceMap: false } },{ loader: 'sass-loader',options: { sourceMap: false } }
]
},...
目前似乎没有造成任何问题