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

[nuxt] usage with Histoire #210

Open
4 tasks done
zarskilukasz opened this issue Jun 7, 2023 · 8 comments
Open
4 tasks done

[nuxt] usage with Histoire #210

zarskilukasz opened this issue Jun 7, 2023 · 8 comments
Labels
✋ help wanted Extra attention is needed 🪛 workaround There is a workaround for this issue

Comments

@zarskilukasz
Copy link

Describe the bug

Hi, I'm using a plugin for Nuxt and I'm having trouble integrating it with Histoire (https://github.com/histoire-dev/histoire).

Reproduction steps:
Run pnpm story:dev

Error:
[nuxt] error caught during app initialization TypeError: Cannot destructure property 'cookieOptions' of '__vite_ssr_import_2__.useRuntimeConfig(...).public.persistedState' as it is undefined. at Object.setup (/nuxt-app/node_modules/.pnpm/@pinia-plugin-persistedstate+nuxt@1.1.1_@pinia+nuxt@0.4.11_pinia@2.1.3/node_modules/@pinia-plugin-persistedstate/nuxt/dist/runtime/plugin.mjs:8:11) at wrapper (/nuxt-app/node_modules/.pnpm/nuxt@3.5.2_@types+node@18.0.0_sass@1.62.1/node_modules/nuxt/dist/app/nuxt.js:191:21) at /nuxt-app/node_modules/.pnpm/nuxt@3.5.2_@types+node@18.0.0_sass@1.62.1/node_modules/nuxt/dist/app/nuxt.js:111:58 at fn (/nuxt-app/node_modules/.pnpm/nuxt@3.5.2_@types+node@18.0.0_sass@1.62.1/node_modules/nuxt/dist/app/nuxt.js:208:44) at Object.runWithContext (/nuxt-app/node_modules/.pnpm/@vue+runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3855:18) at callWithNuxt (/nuxt-app/node_modules/.pnpm/nuxt@3.5.2_@types+node@18.0.0_sass@1.62.1/node_modules/nuxt/dist/app/nuxt.js:213:24) at Object.runWithContext (/nuxt-app/node_modules/.pnpm/nuxt@3.5.2_@types+node@18.0.0_sass@1.62.1/node_modules/nuxt/dist/app/nuxt.js:32:29) at applyPlugin (/nuxt-app/node_modules/.pnpm/nuxt@3.5.2_@types+node@18.0.0_sass@1.62.1/node_modules/nuxt/dist/app/nuxt.js:111:37) at Module.applyPlugins (/nuxt-app/node_modules/.pnpm/nuxt@3.5.2_@types+node@18.0.0_sass@1.62.1/node_modules/nuxt/dist/app/nuxt.js:123:21) at async initApp (/nuxt-app/node_modules/.pnpm/nuxt@3.5.2_@types+node@18.0.0_sass@1.62.1/node_modules/nuxt/dist/app/entry.js:53:7) [nuxt] error caught during app initialization ReferenceError: document is not defined at normalizeContainer (/nuxt-app/node_modules/.pnpm/@vue+runtime-dom@3.3.4/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.js:1440:17) at app.mount (/nuxt-app/node_modules/.pnpm/@vue+runtime-dom@3.3.4/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.js:1371:23) at initApp (/nuxt-app/node_modules/.pnpm/nuxt@3.5.2_@types+node@18.0.0_sass@1.62.1/node_modules/nuxt/dist/app/entry.js:61:14)

When I don't use the @pinia-plugin-persistedstate/nuxt plugin, the error doesn't occur.

Reproduction

https://github.com/zarskilukasz/nuxt-minimal

System Info

System:
    OS: macOS 13.4
    CPU: (8) arm64 Apple M2
    Memory: 601.13 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.5.1 - /usr/local/bin/npm
  Browsers:
    Chrome: 114.0.5735.106
    Firefox: 111.0.1
    Safari: 16.5

Used Package Manager

pnpm

Validations

@zarskilukasz zarskilukasz added the 🔍️ pending triage This issue needs to be looked into label Jun 7, 2023
@prazdevs
Copy link
Owner

prazdevs commented Jun 7, 2023

the provided repo gives me an error on install 🤔

pnpm: /@akryum/tinypool@0.3.1 is an invalid relative dependency path
    at Object.parse2 [as parse] (C:\Users\praz\.node\corepack\pnpm\8.2.0\dist\pnpm.cjs:113619:15)
    at nameVerFromPkgSnapshot (C:\Users\praz\.node\corepack\pnpm\8.2.0\dist\pnpm.cjs:113728:28)
    at addPreferredVersionsFromLockfile (C:\Users\praz\.node\corepack\pnpm\8.2.0\dist\pnpm.cjs:186437:89)
    at getPreferredVersionsFromLockfileAndManifests (C:\Users\praz\.node\corepack\pnpm\8.2.0\dist\pnpm.cjs:186431:7)
    at _installInContext (C:\Users\praz\.node\corepack\pnpm\8.2.0\dist\pnpm.cjs:187332:142)
    at async installInContext (C:\Users\praz\.node\corepack\pnpm\8.2.0\dist\pnpm.cjs:187663:16)
    at async _install (C:\Users\praz\.node\corepack\pnpm\8.2.0\dist\pnpm.cjs:187202:25)
    at async mutateModules (C:\Users\praz\.node\corepack\pnpm\8.2.0\dist\pnpm.cjs:186936:23)
    at async install (C:\Users\praz\.node\corepack\pnpm\8.2.0\dist\pnpm.cjs:186862:24)
    at async installDeps (C:\Users\praz\.node\corepack\pnpm\8.2.0\dist\pnpm.cjs:188821:31)

@zarskilukasz
Copy link
Author

The error you're receiving is likely related to the version of pnpm or node.js.

Please follow the steps below for reproduction => https://stackblitz.com/edit/nuxt-starter-27hxyy

@prazdevs
Copy link
Owner

Ok, I have it working but have several concerns:

  1. Why would pinia be needed for histoire components ?
  2. Is the issue only with this particular pinia plugin ?

I'm also curious if it'd happen as well if we were to use addTemplate again to provide options to runtime. 🤔
Once I tackle this issue, I'll look into this histoire story (yes the pun is intended).

@prazdevs prazdevs added ✋ help wanted Extra attention is needed and removed 🔍️ pending triage This issue needs to be looked into labels Jun 11, 2023
@zarskilukasz
Copy link
Author

zarskilukasz commented Jun 19, 2023

1 .Because I have a very large application and I want to avoid the emit hell by passing props through multiple levels.
2. Yes, it's only a problem with this plugin. A simple test: I remove it from the project and there are no errors.

addTemplate seems like a good idea.

@prazdevs
Copy link
Owner

My question was more "is there another plugin that can cause this" and i think there may be. For some reason, the config options just dont get passed 🤔

@zarskilukasz
Copy link
Author

No. See (https://stackblitz.com/edit/nuxt-starter-27hxyy), I only use Nuxt, Pinia, and Historie - in this setup, I don't have any errors - I add a plugin and I get errors.

@prazdevs prazdevs changed the title Nuxt with histoire [nuxt] usage with Histoire Jul 11, 2023
@prazdevs
Copy link
Owner

Hi, as a temporary workaround, you can disable the plugin for when the project is run by histoire with this

export default defineNuxtConfig({
  modules: [
	// ... other modules
    process.env.HISTOIRE ? undefined : "@pinia-plugin-persistedstate/nuxt",
  ],
})

@prazdevs prazdevs added the 🪛 workaround There is a workaround for this issue label Jul 23, 2023
@kilab
Copy link

kilab commented Jul 27, 2023

@prazdevs in my case, your proposal of a temporary workaround doesn't work. I have a CardTypeProperty component for which I have written a story. This component refers to the store/favourites where I use persistedState :(

Error while collecting story /wrk/stories/cards/CardTypeProperty.story.vue:
ReferenceError: persistedState is not defined
    at /wrk/stores/favourites.ts:17:14
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✋ help wanted Extra attention is needed 🪛 workaround There is a workaround for this issue
Projects
None yet
Development

No branches or pull requests

3 participants