Skip to content

vite: true breaks Nuxt 2 Vuex store #847

@deleteme

Description

@deleteme

Environment

  • Operating System: Darwin
  • Node Version: v18.15.0
  • Nuxt Version: 2.17.0
  • Nitro Version: 2.5.2
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: head, css, plugins, components, buildModules, modules, axios, build, bridge, serverHandlers, devServerHandlers, devServer, typescript, nitro
  • Runtime Modules: @nuxtjs/axios@5.13.6
  • Build Modules: (), @nuxt/bridge@3.0.0-28132497.798694a

Reproduction

https://github.com/deleteme/nuxt2-bridge-vite-bug/tree/vite-with-vuex-store

Steps to reproduce:

  1. Clone a copy of the https://github.com/deleteme/nuxt2-bridge-vite-bug repo and check out the vite-with-vuex-store branch
  2. yarn
  3. yarn dev
  4. visit http://localhost:3000/usestore in the browser
  5. Notice that the Vuex store state is undefined and that the Increment button doesn't work

Describe the bug

After changing vite: true in nuxt.config.js, the Vuex store is not initialized properly when starting a Nuxt 2 server that uses a basic Vuex store. Initial state is undefined. Here's a short video demonstrating the bug:

vite-vuex-store-bug.mov

Something interesting that's happening is that if you restart the server process while having the page open, sometimes the server is able to initialize the Vuex store and the hot reloading can scoop it up.

vite-vuex-store-bug-pt2.mov

Additional context

This is a fresh Nuxt 2 app with the latest bridge added.

  • Vuex store code was lifted from the official docs
  • The only config change is setting vite: true.
  • No errors were thrown in the server log output when running nuxi dev.

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions