storybook icon indicating copy to clipboard operation
storybook copied to clipboard

Problems when running with `/pages` directory

Open obulat opened this issue 1 year ago • 1 comments

When the Nuxt app has a non-empty pages directory, you get the following errors in the console:

vue-router.mjs:35 [Vue Router warn]: No match found for location with path "/iframe.html?id=features-custom-components--custom-template&viewMode=story"
warn @ vue-router.mjs:35
nuxt.js:122 [nuxt] error caught during app initialization Error: Page not found: /iframe.html?id=features-custom-components--custom-template&viewMode=story
    at createError (index.mjs:78:15)
    at router.js:109:29
    at fn (nuxt.js:214:44)
    at Object.runWithContext (runtime-core.esm-bundler.js:2696:18)
    at callWithNuxt (nuxt.js:220:24)
    at nuxt.js:37:41
    at EffectScope.run (reactivity.esm-bundler.js:43:16)
    at Object.runWithContext (nuxt.js:37:31)
    at router.js:109:25
    at vue-router.mjs:3432:52

To reproduce, run example:showcase:dev and go to "http://localhost:6006/?path=/story/features-custom-components--custom-template". You should see this error message displayed twice in the console.

Nuxt only adds the app/router plugin when there are no pages:

https://github.com/nuxt/nuxt/blob/3b907c1c6aa623e88125d731fd267e6a9a89abba/packages/nuxt/src/pages/module.ts#L121-L122

obulat avatar Aug 23 '24 16:08 obulat

@chakAs3 Could you please explain how the custom router setup in the storybook addon works?

In particular, why do we need to:

  • provide our own router: https://github.com/nuxt-modules/storybook/blob/729b372abc4e6e6ab88321cc734fc759d9cfade2/packages/storybook-addon/src/runtime/composables/router.ts#L4-L7
  • provide our own nuxt-link: https://github.com/nuxt-modules/storybook/blob/729b372abc4e6e6ab88321cc734fc759d9cfade2/packages/storybook-addon/src/runtime/components/nuxt-link.ts
  • need to add the iframe page: https://github.com/nuxt-modules/storybook/blob/729b372abc4e6e6ab88321cc734fc759d9cfade2/packages/storybook-addon/src/preset.ts#L104-L110

tobiasdiez avatar Aug 26 '24 13:08 tobiasdiez

Hi,

Same for me. Any update ?

I did this in my nuxt config to remove the error temporary

  hooks: {
    // @TODO: temporary fix for storybook-iframe issue
    'pages:extend': (pages) => {
      pages.push({
        name: 'storybook-iframe',
        path: '/iframe.html',
        redirect: '/',
        mode: 'client',
      })
    },
  },

jamyouss avatar Jan 14 '25 16:01 jamyouss

can confirm im getting the same issue, @jamyouss fix seems to work however with each navigation between stories im logging browser errors that all say the following. i suspect there's an issue with nuxt v4....

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'app')

binaryartifex avatar Jan 25 '25 15:01 binaryartifex

@tobiasdiez Is this resolved, still having the same issue, is there at least any workaround?

shantda avatar Jun 19 '25 07:06 shantda

@tobiasdiez Is this resolved, still having the same issue, is there at least any workaround?

Hard to fix if no one shares a repro…

hacknug avatar Aug 18 '25 10:08 hacknug

Hi @hacknug I put together a repro here https://codesandbox.io/p/devbox/nuxt-storybook-issues-2dsxyz Let me know if this is enough for the investigation.

MrLesk avatar Aug 22 '25 11:08 MrLesk