gpt4 book ai didi

typescript - 如何在 gulp 中显示 webpack 错误

转载 作者:行者123 更新时间:2023-12-05 01:16:49 24 4
gpt4 key购买 nike

我有一个用 webpack 转译的 TypeScript 项目,构建任务由 gulp 驱动。完成这个简单的任务来证明我的问题:

var webpack = require('webpack');
var webpackStream = require("webpack-stream");

gulp.task("check", function() {
return gulp.src("*")
.pipe(webpackStream(require("./webpack.config.js"), webpack))
.pipe(gulp.dest(OUTPUT_DIR));
}
);

现在,当一切正常时,gulp check 工作正常。现在假设我犯了一些编码错误——这个 gulp 任务会发出:

[10:20:02] Starting 'check'...
[hardsource:chrome] Tracking node dependencies with: yarn.lock.
[hardsource:chrome] Reading from cache chrome...
(node:20232) UnhandledPromiseRejectionWarning
(node:20232) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:20232) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[10:20:08] The following tasks did not complete: check
[10:20:08] Did you forget to signal async completion?

这是非常缺乏信息的。如果我从检查任务中删除 .pipe(gulp.dest(OUTPUT_DIR));,我会得到原始错误消息。例如:

[10:35:42] Starting 'check'...
[hardsource:chrome] Tracking node dependencies with: yarn.lock.
[hardsource:chrome] Reading from cache chrome...
[10:35:48] 'check' errored after 5.96 s
[10:35:48] Error in plugin "webpack-stream"
Message:
./myfile.ts
Module build failed: Error: Typescript emitted no output for C:\Projects\myfile.ts.
at successLoader (C:\Projects\***\node_modules\ts-loader\dist\index.js:41:15)
at Object.loader (C:\Projects\***\node_modules\ts-loader\dist\index.js:21:12)
@ ./src/background/background.ts 16:25-54
@ multi ./src/background/backgroundC:\Projects\***\src\myfile.ts
./src/myfile.ts
[tsl] ERROR in C:\Projects\***\src\myfile.ts(305,28)
TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'.
Type 'undefined' is not assignable to type 'number'.
Details:
domainEmitter: [object Object]
domain: [object Object]
domainThrown: false

在 webpackStream 之前或之后向 gulp-load-plugins.logger 添加管道没有帮助。我可以将 gulp 流通过管道传输到 gulp.dest,并仍然获得信息丰富的 webpack 错误消息吗?怎么办?

最佳答案

即使没有 hard-source-webpack-plugin,我也会发生这种情况。这似乎是 webpack-stream 本身的问题:https://github.com/shama/webpack-stream/issues/34

代替:

.pipe(webpackStream(require("./webpack.config.js"), webpack))
.pipe(gulp.dest(OUTPUT_DIR));

将错误处理程序添加到 webpackStream 管道:

.pipe(webpackStream(require("./webpack.config.js"), webpack))
.on('error',function (err) {
console.error('WEBPACK ERROR', err);
this.emit('end'); // Don't stop the rest of the task
})
.pipe(gulp.dest(OUTPUT_DIR));

关于typescript - 如何在 gulp 中显示 webpack 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52381327/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com