maximkoretskiy / postcss-autoreset

PostCSS plugin for automatic rules isolation
MIT License
244 stars 11 forks source link

[object Object] is not a PostCSS plugin #9

Closed mikaa123 closed 8 years ago

mikaa123 commented 8 years ago

Hi there,

When I try to use postcss-autoreset, I have the following error:

Module build failed: Error: [object Object] is not a PostCSS plugin

The way I use it is through webpack. Here is the relevent part of my webpack.config.js:

postcss: function () {
    return [
        require('postcss-autoreset')
    ]
}

After some investigation, it turns out that the compiled version of the source code in my node_modules is:

exports.default = _postcss2.default.plugin('postcss-autoreset', function () {
  [code here]
});

...Which causes the plugin to be attached to the .default property of the exported object.

It turns out this is caused by Babel 6 changing the way it handles defaults.

This could be fixed by changing the way postcss-autoreset exports the plugin, e.g.:

module.exports = postcss.plugin('postcss-autoreset', function (opts) {...

I might work on a PR later on :) The workaround is to use require('postcss-autoreset').default.

maximkoretskiy commented 8 years ago

Thank U. I have fixed it another way.

mikaa123 commented 8 years ago

Thanks for the quick move :) However after testing, the problem remains... :(

The code is effectively wrapped in UMD, but the CommonJS export still doesn't work as expected with Babel 6.

This babel plugin should do the trick though: https://github.com/59naga/babel-plugin-add-module-exports

maximkoretskiy commented 8 years ago

) I`ll dig this problem today.

maximkoretskiy commented 8 years ago

We got it!) babel-plugin-add-module-exports works fine. I`ve added a test to avoid this bug further. @mikaa123 Thank U for a piece of advice and patience. New version is available in npm. Can we close this issue now?

mikaa123 commented 8 years ago

Awesome! Thanks a lot, glad I could help. Let's close this ;)