storybook: Uncaught Error: Singleton client API not yet initialized, cannot call `addArgTypesEnhancer`. with 6.5.0-alpha.39

Describe the bug When I updated to stroybook v.6.5.0-alpha.39 and run npm run stroybook, there is this error:

Uncaught Error: Singleton client API not yet initialized, cannot call `addArgTypesEnhancer`.

System Please paste the results of npx sb@next info here.

  System:
    OS: Linux 5.13 Ubuntu 21.10 21.10 (Impish Indri)
    CPU: (8) x64 Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz
  Binaries:
    Node: 17.5.0 - /usr/bin/node
    Yarn: 1.22.17 - /usr/bin/yarn
    npm: 8.4.1 - /usr/bin/npm
  Browsers:
    Firefox: 96.0
  npmPackages:
    @storybook/addon-actions: ^6.5.0-alpha.39 => 6.5.0-alpha.39 
    @storybook/addon-docs: ^6.5.0-alpha.39 => 6.5.0-alpha.39 
    @storybook/addon-essentials: ^6.5.0-alpha.39 => 6.5.0-alpha.39 
    @storybook/addon-links: ^6.5.0-alpha.39 => 6.5.0-alpha.39 
    @storybook/addon-svelte-csf: ^1.1.0 => 1.1.0 
    @storybook/svelte: ^6.5.0-alpha.39 => 6.5.0-alpha.39 

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (11 by maintainers)

Most upvoted comments

I don’t have the problem anymore after

  • I updated storybook,
  • and did this: github.com/storybookjs/storybook/issues/10887#issuecomment-901109891
Environment Info:

  System:
    OS: Linux 5.13 Ubuntu 21.10 21.10 (Impish Indri)
    CPU: (8) x64 Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz
  Binaries:
    Node: 17.7.0 - /usr/bin/node
    Yarn: 1.22.17 - /usr/bin/yarn
    npm: 8.5.3 - /node_modules/.bin/npm
  Browsers:
    Firefox: 97.0.2
  npmPackages:
    @storybook/addon-docs: ^6.5.0-alpha.46 => 6.5.0-alpha.46 
    @storybook/addon-essentials: ^6.5.0-alpha.46 => 6.5.0-alpha.46 
    @storybook/addon-links: ^6.5.0-alpha.46 => 6.5.0-alpha.46 
    @storybook/addon-svelte-csf: ^1.1.0 => 1.1.0 
    @storybook/svelte: ^6.5.0-alpha.46 => 6.5.0-alpha.46
"storybook-builder-vite": "^0.1.18",

and ./storybook/main.cjs file. : look at config.resolve.dedupe

const preprocess = require("svelte-preprocess");

module.exports = {
  stories: [
    "../src/**/*.stories.mdx",
    "../src/**/*.stories.@(js|jsx|ts|tsx|svelte)",
  ],
  addons: ["@storybook/addon-essentials", "@storybook/addon-links"],
  framework: "@storybook/svelte",
  core: {
    builder: "storybook-builder-vite",
  },
  staticDirs: ["../static"],
  svelteOptions: {
    preprocess: [preprocess({ postcss: true, sourceMap: true })],
  },

  async viteFinal(config, { configType }) {
    // github.com/storybookjs/storybook/discussions/17433
    // BASE_URL est définie dans `.github/workflows/storybook.yml`
    const baseUrl = process.env.BASE_URL;

    if (baseUrl) {
      config.base = `${baseUrl}/`;
    }

    // `Uncaught Error: Singleton client API not yet initialized, cannot call addParameters`
    // github.com/storybookjs/storybook/issues/10887#issuecomment-901109891
    config.resolve.dedupe = ["@storybook/client-api"];

    return config;
  },
};

Hitting the same thing after upgrading from 6.3.12 to 6.4.19. My understanding is that this is caused by multiple @storybook/client-api instances in the node_modules directory however going back to a working state I found that this was the case in both the working as well as the broken state. I have node_modules/@storybook/client-api as well as node_modules/@storybook/preact/node_modules/@storybook/client-api and no idea why the packages of the preact package aren’t hoisted.

Before I go down that rabbit hole any further, could someone confirm that this is indeed the culprit (in that case I would be curious why it worked with 6.3.12 before)?

Scratch all that; it wasn’t the upgrade; some other dependency seemed to have caused mayhem; I will report here when I found out which one it was.

I’m not sure if this will help anyone, but I spent a day with this exact same issue. I believe if you are on a Windows machine the case sensitivity of the path in power shell specifically matters. This caused the issue where the casing was mismatched and gave me this error. When I went back and tabbed through each of the folders within the path, it fixed the issue.

@thadeucity thanks for reporting the error. I have a PR up which should fix it. https://github.com/storybookjs/storybook/pull/17987

@IanVS npx sb@next upgrade works! Thank you very much for your help.

Updated the bug repo with the bug described above: (the bug is fixable downgrading @storybook/* to 6.4.22) https://github.com/thadeucity/storybook-vite-bug

@IanVS I tried as suggested but I’m receiving the same error (also tried without the --builder )

yarn init
yarn add -D vite react react-dom
npx sb@next init --builder @storybook/builder-vite

yarn storybook
//package.json


{
  "name": "vite-storybook",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "@babel/core": "^7.17.9",
    "@storybook/addon-actions": "^6.5.0-alpha.62",
    "@storybook/addon-essentials": "^6.5.0-alpha.62",
    "@storybook/addon-interactions": "^6.5.0-alpha.62",
    "@storybook/addon-links": "^6.5.0-alpha.62",
    "@storybook/builder-vite": "^0.1.28",
    "@storybook/react": "^6.5.0-alpha.62",
    "@storybook/testing-library": "^0.0.9",
    "babel-loader": "^8.2.4",
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "vite": "^2.9.4"
  },
  "dependencies": {},
  "scripts": {
    "storybook": "start-storybook -p 6006",
    "build-storybook": "build-storybook"
  }
}

@IanVS

I’m having the same issue, and managed to duplicate it at https://github.com/thadeucity/storybook-vite-bug

  • System: OS: Windows 10.0.22000.527 CPU: (8) x64 Intel® Core™ i7-11800H CPU @ 4.60GHz

  • Binaries: Node: v16.14.2 Yarn: 1.22.18 npm: 8.5.5

  • Browsers: Firefox: 101.0a1

Figured I would report back as well; I am not using vite but after starting from scratch again, I cannot reproduce this anymore either. This attempt I haven’t tried to move to webpack 5 though, which may have been an issue before considering this appears to have been solved for vite with a dedupe option. If I move on from webpack 4, I will probably try to jump straight to vite though so hopefully I won’t see this again!

Thanks for the vite-fix!

Are either of you using the vite builder, by chance?