Skip to content

[Bug]: Error: Cannot find module 'storybook/internal/csf' when importing eslint-plugin-storybook in v9.0.8+ #31805

Open
@andrew-pledge-io

Description

@andrew-pledge-io

Describe the bug

I have a shared ESLint config package that exports two ESLint v9 flat configs:

  • A Node.js config
  • A React config (including eslint-plugin-storybook)

In Node.js projects, the Storybook plugin is not used, however the import side effects are run since the convention in ESLint is that both configs are exported from the package index.js root.

Since v9.0.8 and later this results in an error:

> eslint --cache

Oops! Something went wrong! :(

ESLint: 9.29.0

Error: Cannot find module 'storybook/internal/csf'
Require stack:
- /Users/example/my-project/node_modules/eslint-plugin-storybook/dist/index.js
    at Function._resolveFilename (node:internal/modules/cjs/loader:1225:15)
    at Function._load (node:internal/modules/cjs/loader:1055:27)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)
    at Module.require (node:internal/modules/cjs/loader:1311:12)
    at require (node:internal/modules/helpers:136:16)
    at src/utils/index.ts (/Users/example/my-project/node_modules/eslint-plugin-storybook/dist/index.js:1:9914)
    at /Users/example/my-project/node_modules/eslint-plugin-storybook/dist/index.js:1:342
    at src/utils/create-storybook-rule.ts (/Users/example/my-project/node_modules/eslint-plugin-storybook/dist/index.js:1:12207)
    at /Users/example/my-project/node_modules/eslint-plugin-storybook/dist/index.js:1:342

In previous versions this error was not present as eslint-plugin-storybook had a dependency on @storybook/csf that was installed transitively.

I don't necessarily think that the new behaviour is incorrect but it is breaking. In any case, it would be nice not to have the plugin crash unless the rule is actually run, so that we don't force storybook to be installed if it's not used.

Reproduction link

NA

Reproduction steps

  1. Install eslint
  2. Install eslint-plugin-storybook
  3. Configure eslint e.g.
// eslint.config.mjs
import storybook from 'eslint-plugin-storybook';
import { defineConfig } from 'eslint/config';

export const react = defineConfig(
  {
    files: ['.storybook/**/*.{ts,tsx}', 'src/**/*.stories.tsx'],
    extends: [storybook.configs['flat/recommended']],
  },
);
  1. Run eslint e.g. npx eslint

System

Storybook Environment Info:

  System:
    OS: macOS 15.5
    CPU: (12) arm64 Apple M2 Max
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - ~/.local/state/fnm_multishells/80191_1750176725187/bin/node
    Yarn: 1.22.22 - ~/.local/state/fnm_multishells/80191_1750176725187/bin/yarn
    npm: 10.9.2 - ~/.local/state/fnm_multishells/80191_1750176725187/bin/npm <----- active
    pnpm: 10.6.5 - ~/.local/state/fnm_multishells/80191_1750176725187/bin/pnpm
  Browsers:
    Chrome: 137.0.7151.104
    Safari: 18.5

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions