Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Storybook doesn't work with Yarn 4 (nodeLinker: pnpm), Vue 3, Vite 5, Storybook 8 #28620

Open
phamhongphuc opened this issue Jul 16, 2024 · 2 comments

Comments

@phamhongphuc
Copy link

phamhongphuc commented Jul 16, 2024

Describe the bug

I'm setting up a new front-end repo with Yarn 4 (nodeLinker: pnpm), Vue 3, Vite 5, Storybook 8.
And I encounter the following error type when starting Storybook or build Storybook.

yarn storybook dev -p 6006

20:47:14 [vite] Pre-transform error: Failed to resolve import ".store/@storybook-vue3-virtual-8d5d8463a2/package/dist/entry-preview.mjs" from "../../../virtual:/@storybook/builder-vite/vite-app.js". Does the file exist?
yarn storybook dev -p 6006 (full log)

D:\Code\issue\vue-vite-storybook-issue>yarn storybook dev -p 6006
storybook v8.2.4

info => Starting manager..
info => Starting preview..
╭───────────────────────────────────────────────────╮
│                                                   │
│   Storybook 8.2.4 for vue3-vite started           │
│   504 ms for manager and 673 ms for preview       │
│                                                   │
│    Local:            http://localhost:6006/       │
│    On your network:  http://192.168.1.20:6006/    │
│                                                   │
╰───────────────────────────────────────────────────╯
20:47:14 [vite] Pre-transform error: Failed to resolve import ".store/@storybook-vue3-virtual-8d5d8463a2/package/dist/entry-preview.mjs" from "../../../virtual:/@storybook/builder-vite/vite-app.js". Does the file exist?
Sourcemap for "/virtual:/@storybook/builder-vite/setup-addons.js" points to missing source files
20:47:14 [vite] Internal server error: Failed to resolve import ".store/@storybook-vue3-virtual-8d5d8463a2/package/dist/entry-preview.mjs" from "../../../virtual:/@storybook/builder-vite/vite-app.js". Does the file exist?
  Plugin: vite:import-analysis
  File: /virtual:/@storybook/builder-vite/vite-app.js:7:84
  5  |
  6  |    const getProjectAnnotations = async (hmrPreviewAnnotationModules = []) => {
  7  |      const configs = await Promise.all([hmrPreviewAnnotationModules.at(0) ?? import('.store/@storybook-vue3-virtual-8d5d8463a2/package/dist/entry-preview.mjs'),
     |                                                                                     ^
  8  |  hmrPreviewAnnotationModules.at(1) ?? import('.store/@storybook-vue3-virtual-8d5d8463a2/package/dist/entry-preview-docs.mjs'),
  9  |  hmrPreviewAnnotationModules.at(2) ?? import('@storybook/addon-links/preview'),
      at TransformPluginContext._formatError (file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/vite-virtual-db36b67538/package/dist/node/chunks/dep-D8YhmIY-.js:49748:41)
      at TransformPluginContext.error (file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/vite-virtual-db36b67538/package/dist/node/chunks/dep-D8YhmIY-.js:49743:16)
      at normalizeUrl (file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/vite-virtual-db36b67538/package/dist/node/chunks/dep-D8YhmIY-.js:64333:23)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/vite-virtual-db36b67538/package/dist/node/chunks/dep-D8YhmIY-.js:64465:39
      at async Promise.all (index 2)
      at async TransformPluginContext.transform (file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/vite-virtual-db36b67538/package/dist/node/chunks/dep-D8YhmIY-.js:64392:7)
      at async PluginContainer.transform (file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/vite-virtual-db36b67538/package/dist/node/chunks/dep-D8YhmIY-.js:49589:18)
      at async loadAndTransform (file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/vite-virtual-db36b67538/package/dist/node/chunks/dep-D8YhmIY-.js:52411:27)
      at async viteTransformMiddleware (file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/vite-virtual-db36b67538/package/dist/node/chunks/dep-D8YhmIY-.js:62175:24)


yarn storybook build

=> Failed to build the preview
[vite]: Rollup failed to resolve import ".store/@storybook-vue3-virtual-8d5d8463a2/package/dist/entry-preview.mjs" from "/virtual:/@storybook/builder-vite/vite-app.js".
yarn storybook build (full log)

D:\Code\issue\vue-vite-storybook-issue>yarn storybook build
storybook v8.2.4

info => Cleaning outputDir: storybook-static
info => Loading presets
info => Building manager..
info => Manager built (334 ms)
info => Building preview..
vite v5.3.4 building for production...
✓ 15 modules transformed.
x Build failed in 134ms
=> Failed to build the preview
[vite]: Rollup failed to resolve import ".store/@storybook-vue3-virtual-8d5d8463a2/package/dist/entry-preview.mjs" from "/virtual:/@storybook/builder-vite/vite-app.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
    at viteWarn (file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/vite-virtual-db36b67538/package/dist/node/chunks/dep-D8YhmIY-.js:65883:17)
    at onRollupWarning (file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/vite-virtual-db36b67538/package/dist/node/chunks/dep-D8YhmIY-.js:65918:5)
    at onwarn (file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/vite-virtual-db36b67538/package/dist/node/chunks/dep-D8YhmIY-.js:65578:7)
    at file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/rollup-npm-4.18.1-ff252ce141/package/dist/es/shared/node-entry.js:18483:13
    at Object.logger [as onLog] (file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/rollup-npm-4.18.1-ff252ce141/package/dist/es/shared/node-entry.js:20131:9)
    at ModuleLoader.handleInvalidResolvedId (file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/rollup-npm-4.18.1-ff252ce141/package/dist/es/shared/node-entry.js:19073:26)
    at ModuleLoader.resolveDynamicImport (file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/rollup-npm-4.18.1-ff252ce141/package/dist/es/shared/node-entry.js:19131:58)
    at async file:///D:/Code/issue/vue-vite-storybook-issue/node_modules/.store/rollup-npm-4.18.1-ff252ce141/package/dist/es/shared/node-entry.js:19018:32
√ Would you like to help improve Storybook by sending anonymous crash reports? ... yes


For some reason (optimization and monorepo) I need to use nodeLinker: pnpm.

I also tried nodeLinker: node_modules. But it leads to another error, check my comment: #28567 (comment)

Reproduction link

https://github.com/issue-reproduction/vue-vite-storybook-issue

Reproduction steps

  1. Clone reproduction repo (branch master).
  2. Use volta or switch to yarn 4.3.1 & node 20.15.1 manually.
  3. Run yarn.
  4. Run yarn storybook or yarn build-storybook.

System

Storybook Environment Info:

  System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz
  Binaries:
    Node: 20.15.1 - ~\AppData\Local\Temp\xfs-44286f6b\node.CMD
    Yarn: 4.3.1 - ~\AppData\Local\Temp\xfs-44286f6b\yarn.CMD <----- active
    npm: 10.7.0 - ~\scoop\apps\volta\current\appdata\tools\image\node\20.15.1\npm.CMD
    pnpm: 7.19.0 - ~\scoop\apps\volta\current\appdata\tools\image\pnpm\7.19.0\bin\pnpm.CMD
  Browsers:
    Edge: Chromium (126.0.2592.102)
  npmPackages:
    @storybook/addon-essentials: ^8.2.4 => 8.2.4
    @storybook/addon-interactions: ^8.2.4 => 8.2.4
    @storybook/addon-links: ^8.2.4 => 8.2.4
    @storybook/addon-onboarding: ^8.2.4 => 8.2.4
    @storybook/blocks: ^8.2.4 => 8.2.4
    @storybook/test: ^8.2.4 => 8.2.4
    @storybook/vue3: ^8.2.4 => 8.2.4
    @storybook/vue3-vite: ^8.2.4 => 8.2.4
    storybook: ^8.2.4 => 8.2.4

Additional context

No response

@phamhongphuc phamhongphuc changed the title [Bug]: Storybook doesn't work with Yarn 4 (nodeLinker: pnpm), Vue 3, Vite 5, Storybook [Bug]: Storybook doesn't work with Yarn 4 (nodeLinker: pnpm), Vue 3, Vite 5, Storybook 8 Jul 16, 2024
@storybookjs storybookjs deleted a comment from greptile-apps bot Jul 17, 2024
@psychobolt
Copy link

psychobolt commented Jul 21, 2024

If your running node-modules linker, I suggest trying to delete your .yarn.lock file and the cached directory in node_modules that Storybook seems to generate. Then run a new install. I know you wish to be on pnpm, but let me know if this helps for the other linker.

@rjohnep
Copy link

rjohnep commented Jul 26, 2024

the same issue for me but with Yarn(pnpm), Vite, React stack

Storybook Environment Info:
  System:
    OS: macOS Sonoma Version 14.5
    CPU: Apple M1 Max
  Binaries:
    Node: v20.15.1
    Yarn: 4.3.1
    npm: 10.7.0
  npmPackages:
    "@storybook/addon-a11y": "^8.2.6",
    "@storybook/addon-actions": "^8.2.6",
    "@storybook/addon-controls": "^8.2.6",
    "@storybook/addon-docs": "^8.2.6",
    "@storybook/addon-interactions": "^8.2.6",
    "@storybook/addon-links": "^8.2.6",
    "@storybook/addon-themes": "^8.2.6",
    "@storybook/builder-vite": "^8.2.6",
    "@storybook/preview-api": "^8.2.6",
    "@storybook/react": "^8.2.6",
    "@storybook/react-vite": "^8.2.6",
    "@storybook/test": "^8.2.6",
    "storybook": "^8.2.6",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "vite": "^5.3.2",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants