Gulp 4.0.2无法编译

发布于 2025-02-05 02:32:53 字数 1145 浏览 2 评论 0原文

我刚刚升级到Angular 4.4.7和Typescript 2.7.2。我正在尝试运行Gulp 4.0.2并编译我的TS文件,但我遇到了此错误。

[12:50:49]您是否忘记了发出异步完成的信号? 节点:事件:498 投掷er; //未经处理的“错误”事件 ^

**
 * Compile TypeScript sources
 */
gulp.task("compile", gulp.series("clean", function () {
    return gulp.src("./App/**/*.ts")
        .pipe(inlineNg2Template({
            base: "/",                  // Angular2 application base folder
            target: "es6",              // Can swap to es5
            indent: 2,                  // Indentation (spaces)
            useRelativePaths: false,     // Use components relative assset paths
            removeLineBreaks: false,     // Content will be included as one line
            templateExtension: ".html", // Update according to your file extension
            templateFunction: false    // If using a function instead of a string for `templateUrl`, pass a reference to that function here
        }))
        .pipe(typescript(tsProject))
        .pipe(ignore("References.js"))
        .pipe(gulp.dest("dist/App"))
        .on('error', function (err) { console.log(err.message); });
}));

I just upgraded to Angular 4.4.7 and typescript 2.7.2. I am trying to run gulp 4.0.2 and compile my ts files but I am getting this error.

[12:50:49] Did you forget to signal async completion?
node:events:498
throw er; // Unhandled 'error' event
^

**
 * Compile TypeScript sources
 */
gulp.task("compile", gulp.series("clean", function () {
    return gulp.src("./App/**/*.ts")
        .pipe(inlineNg2Template({
            base: "/",                  // Angular2 application base folder
            target: "es6",              // Can swap to es5
            indent: 2,                  // Indentation (spaces)
            useRelativePaths: false,     // Use components relative assset paths
            removeLineBreaks: false,     // Content will be included as one line
            templateExtension: ".html", // Update according to your file extension
            templateFunction: false    // If using a function instead of a string for `templateUrl`, pass a reference to that function here
        }))
        .pipe(typescript(tsProject))
        .pipe(ignore("References.js"))
        .pipe(gulp.dest("dist/App"))
        .on('error', function (err) { console.log(err.message); });
}));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

つ可否回来 2025-02-12 02:32:53

上的调用是有问题的,因为 返回一个新流,该流在基础流结束时不会结束。

.on('error', function (err) { console.log(err.message); });

如果删除上面的行,情况将再次起作用。

如果您确实需要处理错误事件,则可以执行此操作,但是您仍然应该从任务功能返回管道流。

gulp.task("compile", gulp.series("clean", function () {
    const stream = gulp.src("./App/**/*.ts")
        .pipe(inlineNg2Template({
            base: "/",                  // Angular2 application base folder
            target: "es6",              // Can swap to es5
            indent: 2,                  // Indentation (spaces)
            useRelativePaths: false,     // Use components relative assset paths
            removeLineBreaks: false,     // Content will be included as one line
            templateExtension: ".html", // Update according to your file extension
            templateFunction: false    // If using a function instead of a string for `templateUrl`, pass a reference to that function here
        }))
        .pipe(typescript(tsProject))
        .pipe(ignore("References.js"))
        .pipe(gulp.dest("dist/App"));
    stream.on('error', function (err) { console.log(err.message); });
    return stream;
}));

请注意,尽管GULP已经从错误事件中打印出消息,但我不会手动重复该过程。

The call to on is problematic, because on returns a new stream that does not end when the underlying stream ends.

.on('error', function (err) { console.log(err.message); });

If you remove the line above, things will work again.

If you really need to handle the error event, you can do it, but you should still return the piped stream from the task function.

gulp.task("compile", gulp.series("clean", function () {
    const stream = gulp.src("./App/**/*.ts")
        .pipe(inlineNg2Template({
            base: "/",                  // Angular2 application base folder
            target: "es6",              // Can swap to es5
            indent: 2,                  // Indentation (spaces)
            useRelativePaths: false,     // Use components relative assset paths
            removeLineBreaks: false,     // Content will be included as one line
            templateExtension: ".html", // Update according to your file extension
            templateFunction: false    // If using a function instead of a string for `templateUrl`, pass a reference to that function here
        }))
        .pipe(typescript(tsProject))
        .pipe(ignore("References.js"))
        .pipe(gulp.dest("dist/App"));
    stream.on('error', function (err) { console.log(err.message); });
    return stream;
}));

Note though that gulp already prints messages from error events, I would not repeat that process manually.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文