Displaying webpack errors within gulp is a simple process

My TypeScript project utilizes webpack for transpilation, and gulp for managing build tasks. Let's consider this simple task to illustrate my query:

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));
    }
);

When everything is functioning correctly, gulp check runs smoothly. However, if I introduce a coding error, the gulp task generates an unhelpful message:

[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?

This error message lacks information. If I remove .pipe(gulp.dest(OUTPUT_DIR)); from the check task, the original error message surfaces:

[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

Adding pipes to gulp-load-plugins.logger before or after webpackStream does not resolve the issue. Is there a way to pipe the gulp stream to gulp.dest and still receive informative webpack error messages? How can this be achieved?

Answer №1

This issue persisted even in the absence of the hard-source-webpack-plugin. It appears to be a glitch specifically related to webpack-stream itself: https://github.com/shama/webpack-stream/issues/34

Instead of following the usual pattern:

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

You can resolve this by incorporating an error handler into the webpackStream pipe:

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

Answer №2

I have decided to share the solution instead of removing the question, as it may be beneficial to someone in the future.

After investigating, we discovered that the problem was caused by our use of a webpack build optimizer known as hard-source-webpack-plugin. It seems that this is a well-known issue, and there is a potential workaround provided in the linked GitHub page.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Breaking up React code within the React.createElement() function

I am encountering an issue with lazily loaded pages or components that need to be rendered after the main page loads. When using createElement(), I receive the following error: LazyExoticComponent | LazyExoticComponent is not assignable to parameter of ty ...

Adding a variable into a sentence

.xmlFieldCreator(`<Field Name="{${kRegion}}" DisplayName="{${kRegion}}" Type="Lookup" List="{${values[1]}}" ShowField="Title" Required="TRUE"/>`); Whenever I attempt to generate a SharePoint List field in this way, the output displays the field name ...

The HTMLInputElement type does not contain a property named 'name'

function handleChange(e) { console.log(e.target.name); } <input name="bb" onChange={handleChange} /> Have you ever wondered why the HTMLInputElement element does not have a name attribute in React? ...

What is the best way to switch to a different screen in a React Native application?

I've recently dived into the world of React Native and embarked on a new project. The initial screen that greets users upon launching the app is the "welcome screen," complete with a prominent 'continue' button. Ideally, clicking this button ...

The first production build generates the bundle code, while all future builds recycle the existing bundle

Recently, I integrated authentication using passport and redux into my project. However, I've been facing an issue where every time I deploy my production-ready code to the server, it keeps using an old build of the bundle file. Interestingly, when I ...

Setting up raw-loader in Angular 7 for loading text files

I am struggling to implement a raw-loader with my Angular 7 in order to import text files into my TypeScript source code. Despite spending several hours researching and attempting various methods, I have been unsuccessful in getting it to work. My journey ...

Out of the blue, the error message "this.http is not defined" popped up

Within my LoginProvider, I have implemented a function that handles the login process and returns the session created as a promise. @Injectable() export class LoginProvider { constructor(public http: HttpClient) { }; public async login(credentia ...

The global variable in TypeScript is not specified; it is initialized within the declaration `declare global{}`

In my TypeScript code, I'm facing a challenge when trying to add a global scope variable. In JavaScript (NodeJS), this process is straightforward: // index.js globalThis.helloWorld = 'Hello World!'; require('./log.js') // log.js c ...

Building a versatile setting within a child component by incorporating TypeScript and deriving state data from the parent component

In my page component, I have set a state called formData. Now, I want to create a context within my form component so that I can utilize it in each child form component. Everything works smoothly without TypeScript. However, when using TypeScript, I encoun ...

Unlock the potential of Angular $http by leveraging TypeScript generics in your web development projects

I have been attempting to implement a generic promise return in my code: public getUserData: () => ng.IPromise <string> = () => { var promise = this.makeRequest<string>('http://someurl.com',null) .then((resp ...

Sending Functions as Props in React Using Typescript from a Parent Component to a Child Component

Trying to pass props from Parent to Child using TypeScript-React but getting an error: "Type 'void' is not assignable to type 'Function'." Parent import React from "react"; import Navbar from "./navbar"; import Main from "./main"; f ...

No response from NgClass after executing the function

In my NgClass function, I make use of an array that is populated in the ngOnInit lifecycle hook. Within ngOnInit, the prepareRezerwation() function creates a variable called colorRezerwation: this.nodeService.getRezerwations(this.minMax).subscribe(re ...

A guide to implementing previousState in React hooks with TypeScript

I am trying to grasp the concept of using previous state with react hooks in typescript. The code snippet provided below does function, however, it throws an error stating: Type 'number' is not assignable to type 'HTMLDivElement'. Whi ...

Triggering blur event manually in Ionic 3

Is there a way to manually trigger the blur event on an ion-input element? The ideal scenario would be with an ionic-native method, but any javascript-based workaround will suffice. My current configuration: Ionic: ionic (Ionic CLI) : 4.0.1 (/User ...

The module 'AppModule' is importing an unexpected value 'AppAsideModule'. To resolve this issue, make sure to include an @NgModule annotation

Recently, I attempted to upgrade my Angular project from version 13 to version 17. However, during the process, I encountered an error stating "Unexpected value 'AppAsideModule' imported by the module 'AppModule'. Please add an @NgModul ...

NgFor displaying only the initial item in the array

I am currently working on creating a dynamic menu in Angular and I have encountered an issue where only the first value in the array is being displayed. How can I modify it to dynamically display all the values from the array? What could be causing this pr ...

Angular does not adhere to globally defined styles

I have defined the margins for mat-expansion-panel in my styles.css file as follows: mat-expansion-panel { margin: 2vh; } Unfortunately, these margins will not be applied to my components unless they are also specified in the local CSS file. Even try ...

Encountering a Typescript error when trying to pass a function as a prop that returns SX style

Imagine a scenario where a parent component needs to pass down a function to modify the styles of a reusable child component: const getStyleProps: StyleProps<Theme> = (theme: Theme) => ({ mt: 1, '.Custom-CSS-to-update': { padding ...

Webpack encounters difficulty in mounting Vue components

Upon compiling a project using Webpack with Vue, an error arises when accessing a page containing a Vue component: [Vue warn]: Failed to mount component: template or render function not defined. Instead of the expected component, this is rendered by Vu ...

You cannot assign the "unknown" type to the "boolean" type

if (queueEntry) { this.inProcess.push(queueEntry); try { await callback(queueEntry); this.inProcess = this.inProcess.filter(queueTmp => queueTmp.id !== queueEntry.id).concat([]); th ...