Two more ways to trigger "nuxt instance unavailable", one inside a pinia store action, one inside a plugin
See original GitHub issueEnvironment
- Operating System:
Darwin
- Node Version:
v18.12.0
- Nuxt Version:
3.0.0-rc.14
,3.0.0
- Nitro Version:
1.0.0
- Package Manager:
npm@8.19.2
- Builder:
vite
- User Config:
css
,modules
,nitro
,runtimeConfig
- Runtime Modules:
@pinia/nuxt@0.4.3
,@pinia/nuxt@0.4.4
- Build Modules:
-
Reproduction
https://stackblitz.com/edit/nuxt-starter-4tlygh?file=plugins%2F01.api.js,stores%2Fmain.js
Describe the bug
There are two points in my code where I get “nuxt instance unavailable”, probably because of calling useNuxtApp
and useRuntimeConfig
repeatedly in nested function calls.
One looks roughly like this:
// inside a plugin
// This works fine
nuxtApp.$log.info('Sending request...');
setTimeout(() => {
// FIXME: nuxt instance unavailable
nuxtApp.$log.info('Got response: Dummy data');
resolve({ dummy: 'data' });
}, 2000);
The other one looks like this:
// inside a store
const { $api, $log } = useNuxtApp();
// This works fine
$log.info('Loading external data...');
const extData = await $api.getData();
// FIXME: nuxt instance unavailable
$log.info('External data loaded.', extData);
Additional context
No response
Logs
Error inside the store looks like this:
[nuxt] [request error] [unhandled] [500] nuxt instance unavailable 10:27:46
at useNuxtApp (./node_modules/nuxt/dist/app/nuxt.mjs:165:13)
at Module.useRuntimeConfig (./node_modules/nuxt/dist/app/nuxt.mjs:173:10) 10:27:40
at log (./utils/logger.js:11:40)
at Object.info (./utils/logger.js:24:5)
at Proxy.loadExternalData (./stores/main.js:23:12)
at async eval (./plugins/02.init.server.js:11:95)
at async Object.callAsync (./node_modules/unctx/dist/index.mjs:72:16)
at async applyPlugin (./node_modules/nuxt/dist/app/nuxt.mjs:97:23)
at async Module.applyPlugins (./node_modules/nuxt/dist/app/nuxt.mjs:107:5)
at async createNuxtAppServer (./node_modules/nuxt/dist/app/entry.mjs:29:7)
Error inside the plugin looks like this:
[nitro] [dev] [uncaughtException] Error: nuxt instance unavailable 10:13:52
at useNuxtApp (/home/projects/nuxt-starter-4tlygh/node_modules/nuxt/dist/app/nuxt.mjs:165:13)
at Module.useRuntimeConfig (/home/projects/nuxt-starter-4tlygh/node_modules/nuxt/dist/app/nuxt.mjs:173:10)
at log (/home/projects/nuxt-starter-4tlygh/utils/logger.js:11:40) 10:13:46
at Object.info (/home/projects/nuxt-starter-4tlygh/utils/logger.js:24:5)
at Timeout.eval [as _onTimeout] (/home/projects/nuxt-starter-4tlygh/plugins/01.api.js:12:24)
at listOnTimeout (https://nuxt-starter-4tlygh.w-credentialless.staticblitz.com/blitz.bba8d0a5a025db74852964077975228459d6d20b.js:6:306541)
at processTimers (https://nuxt-starter-4tlygh.w-credentialless.staticblitz.com/blitz.bba8d0a5a025db74852964077975228459d6d20b.js:6:307364)
at https://nuxt-starter-4tlygh.w-credentialless.staticblitz.com/blitz.bba8d0a5a025db74852964077975228459d6d20b.js:15:258211
at https://nuxt-starter-4tlygh.w-credentialless.staticblitz.com/blitz.bba8d0a5a025db74852964077975228459d6d20b.js:15:258522
Issue Analytics
- State:
- Created 10 months ago
- Comments:13 (2 by maintainers)
Top Results From Across the Web
Plugins - Pinia
A Pinia plugin is a function that optionally returns properties to be added to a store. It takes one optional argument, a context:...
Read more >Environment variables in Nuxt 3 with Pinia - Stack Overflow
In Nuxt 3 is way "harder" to do than in Nuxt 2. Because the Nuxt Instance is not available in places that are...
Read more >Using Modules and Pinia to structure Nuxt 3 app
Pinia is a store library for Vue, it allows you to share a state across components/pages. As we already know what is Pinia,...
Read more >Nuxt 3 full course build and deploy | #Nuxtjs #vue #nuxt3
Learn #nuxtjs with all its new features in the #nuxt3 applicationnuxt 3 Course is for beginners and cover full course to advanced levelIt...
Read more >How to consume APIs with Vuex, Pinia, and Axios
In this article, you'll learn how to consume APIs from a server using Vuex, Pinia, and Axios. We'll cover the following sections:.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
it’ s not a nuxt bug, it’s a feature 😃
why not store nuxt context with reflect-metadata like NestJs or AsyncLocalStorage like mikro-orm store needed data. why is not possible in every place to get context? why I can’t use composables where I want? we command machines or vice versa