question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useNuxtApp() and useRuntimeConfig not available in pinia store during SSR

See original GitHub issue

Environment


  • Operating System: Darwin
  • Node Version: v18.7.0
  • Nuxt Version: 2.16.0-27616340.013f051b
  • Package Manager: yarn@3.2.1
  • Builder: webpack
  • User Config: buildDir, srcDir, bridge, components, ssr, dev, alias, image, generate, head, typescript, publicRuntimeConfig, privateRuntimeConfig, css, loading, loadingIndicator, plugins, buildModules, modules, proxy, axios, vuetify, build, serverHandlers, devServerHandlers
  • Runtime Modules: @nuxtjs/vuetify@1.12.3, @nuxt/image@0.7.1, @nuxtjs/axios@5.13.6, @nuxtjs/proxy@2.1.0, nuxt-social-meta@1.0.0
  • Build Modules: (), nuxt-storm@1.1.3, nuxt-compress@5.0.0, @pinia/nuxt@0.3.1, ~/modules/apolloSSR, @nuxt/bridge@3.0.0-27639120.e7a7f9b

Reproduction

https://github.com/vuejs/pinia/discussions/1526

Describe the bug

I am getting this error image

When running this pinia actions during SSR image

I rolled back to the old this.$nuxt for now to temporarily solve the issue

image

Additional context

The page being loaded uses the default.vue layout which has an apollo query “labels”

image

So that, together with this query causes the error. image

No response

Logs

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:13

github_iconTop GitHub Comments

1reaction
antlionguardcommented, Aug 13, 2022

@stephenjason89 this.$nuxt is unavailable in latest pinia 😦 vuejs/pinia#1526

It’s available now but not have a type support.

0reactions
tubstrrcommented, Dec 10, 2022

I struggled with this for a while, the solution for me was to instantiate the store before I called a method inside of it.

In my use case, I was trying to build Bread Crumbs aided by the current Route, my code looked like this:

export const useBreadCrumbStore = defineStore("breadcrumbs", () => {

  const { currentRoute } = useRouter();

  const makeBreadcrumbList = () => {
    const fullPath = currentRoute.value.fullPath;
    
    fullPath.split("/").forEach((path, index) => {
     ...
    }
  }
}

Which would error out with the Nuxt Instance Unavailable.

What I ended up having to do, was to call the store on my page, before my useSEO composable which actually calls the “makeBreadcumbList” function.

I found this doc on Pinia’s site which clarified what was happening in my case.
https://pinia.vuejs.org/core-concepts/outside-component-usage.html

Hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nuxt.js - Testing Pinia store inside Nuxt3 with vitest throws ...
In your test file, use the vi.mock() function to mock the #imports package. vi.mock('#imports', () => { return { useRuntimeConfig() ...
Read more >
Nuxt Configuration Reference
The folder name for the built site assets, relative to baseURL (or cdnURL if set). This is set at build time and should...
Read more >
How to Quickly Build a Blog with Nuxt and ButterCMS
In this tutorial, you'll learn how you can quickly build a blog using Nuxt and ButterCMS. Hint: It's easier than you think.
Read more >
site:self.nuxt - Reddit post and comment search - SocialGrep
There is also quite some copy-pasting of code during lessons in the video course. Of course the main focus of this course isn't...
Read more >
Introduction to Nuxt 3 modules - DEV Community ‍ ‍
As there is no Nuxt 3 module template repository nor an article how to create one, I thought it would be a good...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found