我有一个用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错误消息吗?怎么样?
答案 0 :(得分:3)
即使没有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));
答案 1 :(得分:1)
我发布解决方案而不是删除问题,以防将来有人使用。
在我们的案例中,问题出在使用名为hard-source-webpack-plugin的Webpack构建加速器。显然,它是known issue-github链接包括一个可能的解决方法。