Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@nuxt/friendly-errors-webpack-plugin

nuxt1.5mMIT2.6.0

Recognizes certain classes of webpack errors and cleans, aggregates and prioritizes them to provide a better Developer Experience

friendly, errors, webpack, plugin

readme

Friendly-errors-webpack-plugin

npm Build Status Build status

Friendly-errors-webpack-plugin recognizes certain classes of webpack errors and cleans, aggregates and prioritizes them to provide a better Developer Experience.

It is easy to add types of errors so if you would like to see more errors get handled, please open a PR!

Getting started

Installation

npm install @nuxt/friendly-errors-webpack-plugin --save-dev

Basic usage

Simply add FriendlyErrorsWebpackPlugin to the plugin section in your Webpack config.

var FriendlyErrorsWebpackPlugin = require('@nuxt/friendly-errors-webpack-plugin');

var webpackConfig = {
  // ...
  plugins: [
    new FriendlyErrorsWebpackPlugin(),
  ],
  // ...
}

Turn off errors

You need to turn off all error logging by setting your webpack config quiet option to true.

app.use(require('webpack-dev-middleware')(compiler, {
  // ...
  logLevel: 'SILENT',
  // ...
}));

If you use the webpack-dev-server, there is a setting in webpack's devServer options:

// webpack config root
{
  // ...
  devServer: {
    // ...
    quiet: true,
    // ...
  },
  // ...
}

If you use webpack-hot-middleware, that is done by setting the log option to false. You can do something sort of like this, depending upon your setup:

app.use(require('webpack-hot-middleware')(compiler, {
  log: false
}));

Thanks to webpack-dashboard for this piece of info.

Demo

Build success

success

eslint-loader errors

lint

babel-loader syntax errors

babel

Module not found

babel

Options

You can pass options to the plugin:

new FriendlyErrorsPlugin({
  compilationSuccessInfo: {
    messages: ['You application is running here http://localhost:3000'],
    notes: ['Some additional notes to be displayed upon successful compilation']
  },
  onErrors: function (severity, errors) {
    // You can listen to errors transformed and prioritized by the plugin
    // severity can be 'error' or 'warn'
  },
  // should the console be cleared between each compilation?
  // default is true
  clearConsole: true,

  // INFO:    all logs
  // WARNING: warnings and errors
  // ERROR:   only errors
  // SILENT:  no log
  logLevel: true,

  // base: default
  // consola: consola adapter
  // can also be npm package name or reporter object
  reporter: 'consola'

  // add formatters and transformers (see below)
  additionalFormatters: [],
  additionalTransformers: []
})

Adding desktop notifications

The plugin has no native support for desktop notifications but it is easy to add them thanks to node-notifier for instance.

var NotifierPlugin = require('@nuxt/friendly-errors-webpack-plugin');
var notifier = require('node-notifier');
var ICON = path.join(__dirname, 'icon.png');

new NotifierPlugin({
    onErrors: (severity, errors) => {
      if (severity !== 'error') {
        return;
      }
      const error = errors[0];
      notifier.notify({
        title: "Webpack error",
        message: severity + ': ' + error.name,
        subtitle: error.file || '',
        icon: ICON
      });
    }
  })
]

API

Transformers and formatters

Webpack's errors processing, is done in four phases:

  1. Extract relevant info from webpack errors. This is done by the plugin here
  2. Apply transformers to all errors to identify and annotate well know errors and give them a priority
  3. Get only top priority error or top priority warnings if no errors are thrown
  4. Apply formatters to all annotated errors

You can add transformers and formatters. Please see transformErrors, and formatErrors in the source code and take a look a the default transformers and the default formatters.

Customize Reporters

Reporter is a class for generating output of errors messages, structure is:

  1. Include following levels log methods: success, info, note, warn, error.
  2. Include method clearConsole for clearing the terminal console.

You can take a look at source code as example base reporter

changelog

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

2.6.0 (2023-11-23)

Bug Fixes

  • bump consola dep to 3.x to align with other nuxt 2 packages (#16) (078d629)
  • doc: update package name in readme sample (#12) (6cf5fbe)

2.5.2 (2021-10-14)

2.5.1 (2021-04-09)

2.5.0 (2019-05-20)

2.4.0 (2018-12-07)

Features

  • display children errors and warnings (812ffe4)

2.3.2 (2018-11-23)

2.3.1 (2018-11-23)

Bug Fixes

  • empty message in module not found error (ac2c233)

2.3.0 (2018-11-03)

2.2.0 (2018-11-03)

Bug Fixes

  • default value for options.logLevel (1ac5b70)
  • ignore WAIT info with consola (93964fa)
  • logLevel can be lower case value (8db42c9)
  • logLevel can be lower case value (27d166b)
  • message in windows (ed4c84b)
  • remove duplicate SyntaxError (8953760)

Features

  • add consola reporter (60e447c)
  • add reporter options (7547af3)
  • add reporters (ccddab5)
  • refactor reporter to standard logger (00c979d)
  • skip branch build in pr (25ca868)
  • consola: use tagged reporter (e414613)
  • sandbox: test with consola.wrapConsole (8d98ae0)

2.1.0 (2018-10-26)

Features

  • sync with friendly-errors-webpack-plugin (75c5c3b)

2.0.2 (2018-03-20)

Features

  • clear console also according to log level (655203d)

2.0.1 (2018-03-20)

Bug Fixes

Features

2.0.0 (2018-03-16)

Bug Fixes

Features

2.4.0 (2018-12-07)

Features

  • display children errors and warnings (812ffe4)

2.3.2 (2018-11-23)

2.3.1 (2018-11-23)

Bug Fixes

  • empty message in module not found error (ac2c233)

2.3.0 (2018-11-03)

Bug Fixes

  • default value for options.logLevel (1ac5b70)
  • ignore WAIT info with consola (93964fa)

Features

  • consola: use tagged reporter (e414613)
  • sandbox: test with consola.wrapConsole (8d98ae0)

2.2.0 (2018-11-03)

Bug Fixes

  • logLevel can be lower case value (8db42c9)
  • logLevel can be lower case value (27d166b)
  • message in windows (ed4c84b)
  • remove duplicate SyntaxError (8953760)

Features

2.1.0 (2018-10-26)

Features

  • sync with friendly-errors-webpack-plugin (75c5c3b)

1.7.0 (2018-04-05)

2.0.2 (2018-03-20)

Features

  • clear console also according to log level (655203d)

2.0.1 (2018-03-20)

Bug Fixes

Features

2.0.0 (2018-03-16)

Bug Fixes

Features