mikedavies-dev
mikedavies-dev

Reputation: 3355

In webpack --watch I only see the first error

When compiling a project in webpack using the --watch option, if the project has an error for example in the less compiler I see that error in the output. Once I correct the error webpack recompiles and all is well.

However if there are multiple errors in the file and I only fix one of them, when webpack re-compiles the code it does not show the new error message, in fact the console does not update at all.

For example:

  1. less file has two errors and save the file
  2. webpack --watch attempts to compile the file and fails, showing the first error
  3. I fix the first error and save
  4. webpack does not show the second error

How can I tell webpack to show the error of the updated build after if fails for a second time?

Upvotes: 3

Views: 746

Answers (1)

mikedavies-dev
mikedavies-dev

Reputation: 3355

It appears that this option is not available on webpack cli but you can easily create a plugin to listen for build events and output any errors, i.e.:

const ConsoleNotifierPlugin = function () {}

ConsoleNotifierPlugin.prototype.compilationDone = (stats) => {
  const log = (error) => {
    console.log(error.error.toString())
  }
  stats.compilation.errors.forEach(log)
}

ConsoleNotifierPlugin.prototype.apply = function (compiler) {
  compiler.plugin('done', this.compilationDone.bind(this))
}

Then just add it to the plugins:

...
plugins: [new ConsoleNotifierPlugin()]
...

Upvotes: 5

Related Questions