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.

nuxtServerInit is never called

See original GitHub issue

generate nuxt project with express, add store/index.js with nuxtServerInit:

import axios from 'axios'
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export const state = () => {
    return {
    }
}

export const mutations = {

}

export const  actions = {
    // nuxtServerInit is called by Nuxt.js before server-rendering every page
    async nuxtServerInit({dispatch, commit}, {req}) {
        console.log("nuxtServerInit()");
    },
    async test({ commit }, { v }) {
        console.log('store test: ', v)
    }
  }

but method test() runs fine from this.$store.dispatch(‘test’…)

probably nuxtServerInit() never called from nuxt.render

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
j172993563commented, Jun 8, 2019

@F145h Thanks.The issue was occurred as you said. I changed the mode from ‘spa’ to “Universal” in nuxt.config.js. The problem was solved.

0reactions
renardsascommented, Oct 10, 2020

@iloyos , I think your problem comes from the config file (nuxt.config.js):

/*
** ssr
** @see https://go.nuxtjs.dev/ssr-mode
** / 
{ 
  ssr: false
}

=> Doc : https://nuxtjs.org/guides/configuration-glossary/configuration-ssr Set it to true and that will solve your problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nuxtServerInit is not calling on production server - Nuxt.js
I run npm run build and then pm2 start npm --name "nuxt-project" -- start I am using pm2 for the production mode. Even...
Read more >
Creating Server-side Rendered Vue.js Apps Using Nuxt.js
There is a problem: We see the original state for a second while the API runs. Later, we will use a solution provided...
Read more >
Using nuxtServerInit in Vuex to Fetch Component Data
The nuxtServerInit action is called in universal mode on the sever ... data and the request will not need to be made again...
Read more >
NuxtServerInit not working on Vuex module mode - Nuxt.js ...
js]." posts.js export const actions = { // This isn't called unless it is "chained" nuxtServerInit(vuexContext, context) { ...
Read more >
Nuxt Lifecycle
nuxtServerInit. Vuex action that is called only on server-side to pre-populate the store; First argument is the Vuex context, second argument is the...
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