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]: [vite] Internal server error: Missing "./preview.js" specifier in "@storybook/react" package #23338

Closed
kamiljurek opened this issue Jul 6, 2023 · 17 comments · Fixed by vitejs/vite#13734

Comments

@kamiljurek
Copy link

kamiljurek commented Jul 6, 2023

Describe the bug

I am experiencing this error.

Using NX 16.5.0, storybook 7.0.26
commands done:

  1. npm install -D @nx/storybook
  2. nx g @nx/storybook:configuration {project_name}
  3. nx storybook {project_name}

in the network tab in developer console I see the call:
http://localhost:4400/virtual:/@storybook/builder-vite/vite-app.js which returns 404
added test component is listed on the left side but endless loading circle is showed in the center:
image

component doesn't render at all.

any hints?

To Reproduce

No response

System

logs:
2:20:07 PM [vite] Internal server error: Missing "./preview.js" specifier in "@storybook/react" package Plugin: vite:import-analysis File: /virtual:/@storybook/builder-vite/vite-app.js at e (file:///Users/kajurek/repo/bdb/frontend/bdb-monorepo/node_modules/vite/dist/node/chunks/dep-1d3a4915.js:21424:25) at n (file:///Users/kajurek/repo/bdb/frontend/bdb-monorepo/node_modules/vite/dist/node/chunks/dep-1d3a4915.js:21424:627) at o (file:///Users/kajurek/repo/bdb/frontend/bdb-monorepo/node_modules/vite/dist/node/chunks/dep-1d3a4915.js:21424:1297) at resolveExportsOrImports (file:///Users/kajurek/repo/bdb/frontend/bdb-monorepo/node_modules/vite/dist/node/chunks/dep-1d3a4915.js:28705:20) at resolveDeepImport (file:///Users/kajurek/repo/bdb/frontend/bdb-monorepo/node_modules/vite/dist/node/chunks/dep-1d3a4915.js:28724:31) at tryNodeResolve (file:///Users/kajurek/repo/bdb/frontend/bdb-monorepo/node_modules/vite/dist/node/chunks/dep-1d3a4915.js:28415:20) at Context.resolveId (file:///Users/kajurek/repo/bdb/frontend/bdb-monorepo/node_modules/vite/dist/node/chunks/dep-1d3a4915.js:28176:28) at async Object.resolveId (file:///Users/kajurek/repo/bdb/frontend/bdb-monorepo/node_modules/vite/dist/node/chunks/dep-1d3a4915.js:44099:32) at async ModuleGraph._resolveUrl (file:///Users/kajurek/repo/bdb/frontend/bdb-monorepo/node_modules/vite/dist/node/chunks/dep-1d3a4915.js:64784:46) at async file:///Users/kajurek/repo/bdb/frontend/bdb-monorepo/node_modules/vite/dist/node/chunks/dep-1d3a4915.js:64702:45 at async Promise.all (index 1) at async ModuleGraph.updateModuleInfo (file:///Users/kajurek/repo/bdb/frontend/bdb-monorepo/node_modules/vite/dist/node/chunks/dep-1d3a4915.js:64678:13) at async TransformContext.transform (file:///Users/kajurek/repo/bdb/frontend/bdb-monorepo/node_modules/vite/dist/node/chunks/dep-1d3a4915.js:42016:39) at async Object.transform (file:///Users/kajurek/repo/bdb/frontend/bdb-monorepo/node_modules/vite/dist/node/chunks/dep-1d3a4915.js:44175:30) at async loadAndTransform (file:///Users/kajurek/repo/bdb/frontend/bdb-monorepo/node_modules/vite/dist/node/chunks/dep-1d3a4915.js:54810:29) ^C%

Additional context

No response

@marcovanharten-cpi
Copy link

@kamiljurek . We are running into the same issue

@silltho
Copy link

silltho commented Jul 6, 2023

Can confirm having the same issue. Downgrading storybook and addons to 7.0.25 does not work. We are also using nx but just for task execution, but i'm also facing the error when executing "storybook dev -p 6006" from npm scripts.

Example Config:

import { StorybookConfig } from '@storybook/react-vite'
import { mergeConfig } from 'vite'

const config: StorybookConfig = {
  framework: {
    name: '@storybook/react-vite',
    options: {},
  },
  stories: ['../src/**/*.stories.@(tsx|mdx)'],
  addons: [
    '@storybook/addon-docs',
    '@storybook/addon-actions',
    '@storybook/addon-controls',
    '@storybook/addon-viewport',
    '@storybook/addon-backgrounds',
  ],
  async viteFinal(config) {
    const mergedConfig = mergeConfig(config, {
      build: {
        sourcemap: false, // prevent node out of memory error
      },
    })
    return mergedConfig
  },
}

export default config

@marcovanharten-cpi
Copy link

Our team confirmed the issue is something with our vite version. Downgrading to "vite": "~4.3.9" patched up the issue for now... (not the greatest solution ofcourse)

@Mahonism
Copy link

Mahonism commented Jul 6, 2023

Just wanted to add the same answer as marcovanharten-cpi. We have the same issue and vite 4.3.9 is working with that issue. so we can confirm the workaround

@silltho
Copy link

silltho commented Jul 6, 2023

Our team confirmed the issue is something with our vite version. Downgrading to "vite": "~4.3.9" patched up the issue for now... (not the greatest solution ofcourse)

Thx vite downgrade to 4.3 solved the issue for now. ❤️

@TessavWalstijn
Copy link

I have been pulling my hear for almost 5 hours >..<

Locking Vite on 3.9 fixed it!

@patak-dev
Copy link

This issue should be fixed in vite@4.4.1

@valentinpalkovic
Copy link
Contributor

Closing as this issue has been resolved upstream.

@maaaathis
Copy link

maaaathis commented Dec 1, 2023

This error occurs again with storybook v7.6.2, nx v17.1.3 & vite 5.0.4.

@insidewhy
Copy link

insidewhy commented Dec 2, 2023

I'm getting something similar but like this:

Missing "./dist/entry-preview.mjs" specifier in "@storybook/react" package

with vite 4.5.0, vite 5.0.4, vite 4.3.9 and vite 4.4.1

@ant-dep
Copy link

ant-dep commented Dec 14, 2023

having with vite 5.0.9 and Storybook 7.6.4

=> Failed to build the preview
Error: Missing "./preview" specifier in "@storybook/react" package  with vite 5.0.9 and Storybook 7.6.4

edit (29/12/23): same with 5.0.10 and Storybook 7.6.6

@ant-dep
Copy link

ant-dep commented Dec 29, 2023

having with vite 5.0.9 and Storybook 7.6.4

=> Failed to build the preview
Error: Missing "./preview" specifier in "@storybook/react" package  with vite 5.0.9 and Storybook 7.6.4

edit (29/12/23): same with 5.0.10 and Storybook 7.6.6

I fixed it by removing ViteFinal optmize deps from .storybook/main.ts

I had 👇

  viteFinal: async (config) => {
    config.optimizeDeps = {
      ...config.optimizeDeps,
      include: [
        '@bbbtech/storybook-formik',
        '@storybook/react/preview',
        '@storybook/addon-docs/preview',
        '@storybook/addon-essentials/backgrounds/preview',
        '@storybook/addon-essentials/measure/preview',
        '@storybook/addon-essentials/outline/preview',
        '@storybook/addon-essentials/highlight/preview',
        '@storybook/addon-actions/preview',
        'storybook-addon-pseudo-states/preview'
      ]
    };

    return config;
  }

@Sinakhx
Copy link

Sinakhx commented Jan 6, 2024

removing node_modules & .lock files & re-installing the packages fixed the issue for me.

@ant-dep
Copy link

ant-dep commented Jan 6, 2024

Storybook 7.6.7 fixes this :)

@Darkspice
Copy link

Update package @storybook/react to 7.6.9 helped fix this issue.

@enix79
Copy link

enix79 commented Jan 23, 2024

I was able to fix this issue by running "npx storybook automigrate" and realizing, that my storybook deps are note deduped:
image

After I have run "npm dedupe", that error has gone.

I had issues with both react and react-vite packages:
image

@silouanwright
Copy link

If anyone comes across this issue, look very carefully at your storybook main.js file. You may have added some level of configuration that was necessary for older Storybook versions, but not for the latest ones.

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

Successfully merging a pull request may close this issue.