RoccoC / webpack-build-notifier

A Webpack plugin that generates OS notifications for build steps using node-notifier.
MIT License
162 stars 24 forks source link

WebpackBuildNotifierPlugin is not a constructor #39

Closed muuvmuuv closed 5 years ago

muuvmuuv commented 5 years ago

When running webpack with ts-node (webpack.config.ts) I get this error:

      new BuildNotifier({
      ^
TypeError: webpack_build_notifier_1.WebpackBuildNotifierPlugin is not a constructor

In a basic JS node application everything seems fine. Maybe this is because webpack-build-notifier in not a class?

I import it with import { WebpackBuildNotifierPlugin as BuildNotifier } from 'webpack-build-notifier'.

If it is because it is not a class, it would be great if someone would rewrite it to a class. Here is an example of a good TypeScript written webpack plugin: https://github.com/johnagan/clean-webpack-plugin/blob/master/src/clean-webpack-plugin.ts

RoccoC commented 5 years ago

Can you try changing the import to:

import BuildNotifier from 'webpack-build-notifier';

muuvmuuv commented 5 years ago

This was the method I used before, but now it seems like it does not work anymore...

Module '"..../node_modules/webpack-build-notifier/index"' has no default export. ts(1192)

RoccoC commented 5 years ago

Ah, looks like there was no default export in the TS definition. Can you please upgrade to 0.1.32 and try again please?

muuvmuuv commented 5 years ago

Nope, still getting this error above. You can have a look at my webpack file here: https://github.com/muuvmuuv/vscode-sundial/blob/master/webpack.config.ts.off

RoccoC commented 5 years ago

OK -- found that the TS definition implied that this plugin is exported as a default ES6 export, which isn't the case (it's currently a commonJS module). I corrected the definition, but now you will need to upgrade to version 1.0.0 and change your import to import * as WebpackBuildNotifierPlugin from 'webpack-build-notifier'.

Let me know how it goes!

muuvmuuv commented 5 years ago

@RoccoC did u pushed the version to NPM? I get no update. np. I will add it manually in my node_modules for testing

muuvmuuv commented 5 years ago

Yes, copied index.d.ts and index.js content into my node_modules and it worked! Thanks :)

muuvmuuv commented 5 years ago

Nevermind, I forgot to do npm i webpack-build-notifier@latest..

RoccoC commented 5 years ago

Glad it worked out! Thanks!