mattlewis92 / webpack-filter-warnings-plugin

Allows you to hide certain warnings from webpack compilations
MIT License
27 stars 10 forks source link

Constructor is Default Export, Not a Named Export #4

Open dhurlburtusa opened 5 years ago

dhurlburtusa commented 5 years ago

Version: 1.2.1 Syntax: CommonJS

Using the following:

const { FilterWarningsPlugin } = require('webpack-filter-warnings-plugin');

...
  plugins: [
    new FilterWarningsPlugin(...),
  ],
...

I get a "TypeError: FilterWarningsPlugin is not a constructor" error message.

Changing "import" to:

const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');

fixes the issue.

So, either the documentation (i.e., the README.md) is incorrect, or the package was built incorrectly.

In the dist directory of webpack-filter-warnings-plugin in my node_modules, I have the following files:

// cjs.js
'use strict';

module.exports = require('./index').default;

and

// index.js
'use strict';

...

exports.default = FilterWarningsPlugin;

The main property in package.json has "dist/cjs.js".

I am going to assume the README.md is incorrect, and I am going to create a PR to update it.

dhurlburtusa commented 5 years ago

Oh, I see what is going on. The documentation is for the new, unreleased changes for the change to TypeScript. But the latest release is prior to the TypeScript changes.

A way to mitigate this issue of the documentation being out of sync with the latest released code is to follow something like GitFlow where the documentation and code on the master branch represent the latest release. Then the develop branch can have the updated documentation and code.

Be sure to leave the repo's default branch as master so that it is what is seen by default.

cdeutsch commented 4 years ago

Oh man. Just went through this same thing. 🤦‍♂

Thanks for filing this issue 👍