Storybook: Question: ESLint no-undef errors for `module` parameter

Created on 28 May 2018  路  3Comments  路  Source: storybookjs/storybook

Bug or support request summary

I'm just starting out with storybook, and am having difficulty understanding what the module parameter to configure(loadStories, module); and storiesOf('Button', module) is for, and how people typically deal with it being reported by ESLint. I've looked through a few of the example repos, and it doesn't seem like other projects are having to disable the rule. I assume there's some babel magic going on that injects a definition for module. But if that's so, why can't babel also inject the parameter to configure and storiesOf?

What is the "standard" way to handle these linting errors? Are there some docs explaining module and how to deal with it somewhere that I haven't found?

Most helpful comment

I feel like an idiot and am tempted to delete this issue, but instead I'll make a note here for any future travelers who might come across this problem. The module parameter is a node global. So adding the node eslint environment solves the problem (either in a config file, or a config comment).

All 3 comments

I feel like an idiot and am tempted to delete this issue, but instead I'll make a note here for any future travelers who might come across this problem. The module parameter is a node global. So adding the node eslint environment solves the problem (either in a config file, or a config comment).

But those storybook files don't actually execute in Node. They are client files.

I suggest using commonjs instead of node for storybook.

  • In .eslintrc add env: { "commonjs": true } (This will apply to all files that are linted)

  • Or at the top of the file add /* eslint-env commonjs */

I went for the latter, only enabling commonjs in those specific files that need it. Because I want to discourage the use of require() in the bulk of the project, in favour of import. But you may be happy to use require/commonjs everywhere.

By way of contrast, in webpack.config.js I do use /* eslint-env node */ because that is executed by Node.

tks

Was this page helpful?
0 / 5 - 0 ratings