Storybook: addon-a11y in config crashes with non-existent addons channel

Created on 19 Mar 2019  路  11Comments  路  Source: storybookjs/storybook

Describe the bug
I'm trying to setup addon-a11y, however it crashes if I use the addDecorator in my config.js

Eg:

import { withA11y } from '@storybook/addon-a11y';
import { withKnobs } from '@storybook/addon-knobs';
import { addDecorator, configure } from '@storybook/react';
import React from 'react';

const req = require.context('../src', true, /\.story\.tsx$/);

function loadStories() {
  req.keys().forEach(filename => req(filename));
}


addDecorator(withKnobs);
addDecorator(withA11y);

configure(loadStories, module);

Which crashes with:

bootstrap:781 Uncaught Error: Accessing non-existent addons channel, see https://storybook.js.org/basics/faq/#why-is-there-no-addons-channel
    at AddonStore.getChannel (index.js:30)
    at Object.<anonymous> (index.js:46)
    at Object.../../node_modules/@storybook/addon-a11y/dist/index.js

Seems to me that the channel is not ready yet here.

However if I move the addDecorator(withA11y); to any story for example to a SampleComponent.story.tsx everything works as expected. However I really want to configure it in my config.js.

What am I doing wrong?

To Reproduce
Use addDecorator(withA11y) in config.js

Expected behavior
To not crash

System:

  • OS: MacOS
  • Device: Macbook Pro 2016
  • Browser: Chrome
  • Framework: React
  • Addons: a11y
  • Version: 5.0.3
a11y has workaround question / support

Most helpful comment

I'm having the same issue. Seems to be an issue with the order of imports 馃

This doesn't work for me:

import { withA11y } from '@storybook/addon-a11y';
import { addDecorator, configure } from '@storybook/react';

However, this works:

import { addDecorator, configure } from '@storybook/react';
import { withA11y } from '@storybook/addon-a11y';

I'm able to reproduce it with examples/official-storybook. Not sure if this is the expected behavior.

All 11 comments

For now, I found a workaround. Just export a function that returns a story with the addDecorator and use that function in your storybook's files.

I'm in Vue and TypeScript but it should works fine in javascript if you remove the typings.

export function storiesOfComponent(storyName: string, module: NodeModule): Story {
    const story: Story = storiesOf(storyName, module);
    story.addDecorator(withA11y as any);

    return story;
}

We're using withA11y globally in examples/official-storybook inside the repo. Not sure what the difference is, but maybe you can look at that example to see if you can find any differences.

I'm having the same issue. Seems to be an issue with the order of imports 馃

This doesn't work for me:

import { withA11y } from '@storybook/addon-a11y';
import { addDecorator, configure } from '@storybook/react';

However, this works:

import { addDecorator, configure } from '@storybook/react';
import { withA11y } from '@storybook/addon-a11y';

I'm able to reproduce it with examples/official-storybook. Not sure if this is the expected behavior.

That's pretty weird. Anybody of my a11y peeps wanna track this down? @CodeByAlex @jsomsanith @Armanio

Quick investigation only :

  • import of addDecorator from @storybook/react executes app/react/src/client/preview/index.js that calls @storybook/core/client > start() that sets the channel. That's why it works when it is imported before a11y.
  • import of anything from @storybook/addon-a11y executes a addons.getChannel() that has not been set yet. It is used to set a listener to execute an aXe run on EVENTS.REQUEST.

Quick fix is what is suggested by @deini, but yes, need to find a way to register the listener once the channel is available.

@jsomsanith once again you do not disappoint. 馃槃 Thank you kindly!

Intresting. I'll try fix it in as soon as possible.

Hi guys! Sorry for my long absence. I create PR, check it. 猬嗭笍

Not sure if this fix has worked. I'm using v5.0.6 and having the same issue.

@trippingtarballs the change hasn't been released yet

w00t!! I just released https://github.com/storybooks/storybook/releases/tag/v5.1.0-alpha.21 containing PR #6354 that references this issue. Upgrade today to try it out!

Because it's a pre-release you can find it on the @next NPM tag.

Closing this issue. Please re-open if you think there's still more to do.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

levithomason picture levithomason  路  3Comments

rpersaud picture rpersaud  路  3Comments

shilman picture shilman  路  3Comments

xogeny picture xogeny  路  3Comments

tirli picture tirli  路  3Comments