[🐞] Storybook integration not working
Which component is affected?
Starters / CLI
Describe the bug
I installed the fresh qwik project and I want to add the storybook integration to my project, but when I try it fails to run, and shows this error message: SB_CORE-SERVER_0002 (CriticalPresetLoadError): Storybook failed to load the following preset: storybook-framework-qwik/preset.
can you guys take a look? thank you! @manucorporat @igorbabko
Reproduction
https://github.com/ardiansah47/qwik-storybook
Steps to reproduce
- Clone the project
- Run pnpm install
- Then run pnpm storybook
System Info
System:
OS: macOS 15.3
CPU: (8) arm64 Apple M3
Memory: 249.25 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 23.5.0 - ~/.nvm/versions/node/v23.5.0/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v23.5.0/bin/npm
pnpm: 9.15.3 - /opt/homebrew/bin/pnpm
Browsers:
Brave Browser: 132.1.74.51
Chrome: 133.0.6943.53
Safari: 18.3
npmPackages:
@builder.io/qwik: ^1.12.0 => 1.12.0
@builder.io/qwik-city: ^1.12.0 => 1.12.0
typescript: 5.4.5 => 5.4.5
undici: * => 7.3.0
vite: 5.3.5 => 5.3.5
Additional Information
Here the images that show the console when you try to run the storybook
Hello @ardiansah47 I have the same issue. Did you find a solution?
Hi! @marloneth I haven’t found a solution yet, but I’ll update here if I do!
My understanding is the line of code failing is coming from a different repository entirely, a project maintained by a community member
https://github.com/literalpie/storybook-framework-qwik/blob/0d237ce4e849d0f3f4e62bd4c006b7dffe888a76/packages/storybook-framework-qwik/src/preset.ts#L7
I was able to reproduce the same problem with a brand new qwik project.
mkdir reproduce-7325
cd reproduce-7325
npm init -y
npm run create qwik@latest
npm run qwik add storybook
npm run storybook
I was able to get storybook working by editing the node_modules/storybook-framework-qwik/dist/preset.js
--- a/preset.js
+++ b/preset.js
@@ -3,6 +3,8 @@ import { mergeConfig } from "vite";
import { QWIK_LOADER } from "@builder.io/qwik/loader";
import { qwikDocgen } from "./docs/qwik-docgen.js";
import { dirname, join } from "path";
+import { createRequire } from "module";
+const require = createRequire(import.meta.url);
const wrapForPnP = (input) => dirname(require.resolve(join(input, "package.json")));
This makes me believe the problem comes from trying to use CommonJS inside an ESM module.
Indeed this is a third-party problem. One solution would be to create a pnpm patch for it in the adder, but it would be best if @literalpie accepts the PR and crafts a new release
Sorry for being a bottleneck. 0.4.2 has been released with the possible fix
commented on https://github.com/literalpie/storybook-framework-qwik/pull/80
But also sharing here that it is still not working. It looks like build for storybook-framework-qwik may not have worked, the published version of the js does not have the fix:
package preset.js from:
https://unpkg.com/[email protected]/dist/preset.js
import { mergeConfig } from "vite";
import { QWIK_LOADER } from "@builder.io/qwik/loader";
import { qwikDocgen } from "./docs/qwik-docgen.js";
import { dirname, join } from "path";
const wrapForPnP = (input) => dirname(require.resolve(join(input, "package.json")));
I'm going to close this here because we can't do anything about this