Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Notifications example in the readme doesn't work #49

Closed
wojtiku opened this issue Apr 28, 2017 · 3 comments
Closed

Notifications example in the readme doesn't work #49

wojtiku opened this issue Apr 28, 2017 · 3 comments

Comments

@wojtiku
Copy link

wojtiku commented Apr 28, 2017

The example from the readme doesn't work.

var NotifierPlugin = require('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: context.pkg.name,
        message: severity + ': ' + error.name,
        subtitle: error.file || '',
        icon: ICON
      });
    }
  })
]

title property passed to the notifier.notify uses a variable context that is not defined and the whole thing fails.

I tried googling this and looking into the code but haven't came up with anything. Where is context supposed to come from?

Thanks in advance!

@christophehurpeau
Copy link
Collaborator

christophehurpeau commented Apr 28, 2017

You should have something like that in your webpack.config.js:

const NotifierPlugin = require('friendly-errors-webpack-plugin');
const notifier = require('node-notifier');
const ICON = path.join(__dirname, 'icon.png');
const pkg = require('./package.json');

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

@wojtiku
Copy link
Author

wojtiku commented Apr 28, 2017

Ah, thanks! I thought context.pkg.name is some webpack thingie that would return me a name of the package that caused the error :).

@ghost
Copy link

ghost commented Dec 23, 2019

@christophehurpeau I made a PR. Docs are shit and you repeat the same shit here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants