storybook-eol / storybook-addons

REPO/PACKAGE MOVED - Storybook addons store
https://github.com/storybooks/storybook/tree/master/lib/addons
MIT License
3 stars 2 forks source link

Addon Error "Cannot read property 'emit' of null" #1

Closed thani-sh closed 8 years ago

thani-sh commented 8 years ago

Related issue: https://github.com/mthuret/storybook-addon-specifications/issues/1

This issue is somewhat weird:

@tomitrescak got the error message

Cannot read property 'emit' of null

Which means that the addons variable here must be already available and addons.getChannel() call was successful. Which means @kadira/storybook-addons was already available.

The weird thing is that it started working once he installed @kadira/storybook-addons. Maybe it was some node module version mixups or its something else.

I checked the mthuret/storybook-addon-specifications code and the way it's using addons.getChannel() is fine. I tried setting up this addon with the react-button repo and it also worked fine.

cc: @arunoda @roonyh

arunoda commented 8 years ago

We need to check with @tomitrescak he is using NPM2?

arunoda commented 8 years ago

We need to do some webpack hack and try to load the same @kadira/storybook-addons in all the cases. (Using webpack's alias)

Then we may use @kadira/storybook-addons as a peer dependancy. Not sure this'll fix that issue, then we know everyone on the same page.

thani-sh commented 8 years ago

All addons have @kadira/storybook-addons as a peer dependency and @kadira/storybook has it as a dependency. So it should work fine, right?

arunoda commented 8 years ago

@mnmtanish Ah yes. In that case, it should work properly. May be the version of @kadira/storybook-addons in the @kadira/storybook is a older one. Which don't have that emit method.

So, when the user installed @kadira/storybook-addons manually it will show up properly.

thani-sh commented 8 years ago

The emit method comes from the channel. From the error we can see that the user got null instead of the channel. This can happen when multiple versions of @kadira/storybook-addons gets loaded somehow. I think the one on react-storybook gets the addons.setChannel call and the one (somehow) loaded by the addon gets the addons.getChannel call.

Is there any node feature to make sure only one version of a module gets loaded? Is it okay to use a global variable to check whether multiple versions are loaded?

tomitrescak commented 8 years ago

Guys, the error was that I was using older version of storybook ... shame on me :/

arunoda commented 8 years ago

Thanks @tomitrescak. The think I guess might be correct. I think we can close this now.

darthtrevino commented 8 years ago

FYI, if you run into this while developing addons, I had to update .storybook/webpack.config.js:

const path = require('path');
module.exports = {
  ...<your wepback conf>...
  resolve: {
    alias: {
      '@kadira/storybook-addons': path.join(__dirname, '../node_modules/@kadira/storybook-addons'),
    },
  },
};