"Organizing the services in your project" example code is not SSR compatible
See original GitHub issueI believe it’s not a bug in Feathers-Vuex itself and just a problem with the example code.
Expected behavior
The guide provides a code example for Organizing the services in your project
with the use of require.context
.
Actual behavior
It works fine in the browser but fails on the server when used in SSR mode.
When you run the server, then open the page in browser and hit refresh, the server tries to redefine store
property on the services managed by this feature. The result is:
{ TypeError: Cannot redefine property: store
at Function.defineProperties (<anonymous>)
at setupStore (/home/gusto/rpg/services-test/node_modules/feathers-vuex/lib/service-module/service-module.js:128:14)
Using service('users')
without require.context
behaves properly.
I did try to fix it but failed.
Repro
https://github.com/gustojs/feathers-vuex-services-test
System configuration
Linux Mint Feathers-Vuex 1.3 Nuxt 1.4 Node 10.1 npm 6.0.1
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Server-side rendering support / SSR · Issue #412 - GitHub
I created a web app using Amplify+React. Now I need to work on the SEO, but this requires server-side rendering (I am using ......
Read more >Angular 7 - Service Worker PWA + SSR not working on server
The problem is, service worker is tried to be registered on the server side, which is not supported. What you can do is...
Read more >How to implement server-side rendering in your React app in ...
In this tutorial, we'll use server-side rendering to deliver an HTML response ... SSR can improve performance if your application is small.
Read more >Creating Server-side Rendered Vue.js Apps Using Nuxt.js
Nuxt.js is based off an implementation of SSR for the popular React library called Next. ... Not much different from creating a Vue...
Read more >Getting Started with Server-Side Rendering (SSR) - JavaScript
The withSSRContext utility creates an instance of Amplify scoped to a single request ( req ) using those cookie credentials. For client-side code...
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 FreeTop 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
Top GitHub Comments
Just ran into this same problem and now have a minimal solution.
Documentation code issues:
Issue 1 is that the main file exports
new Vuex.Store(...)
directly but should be exporting a function,createStore
that returns the instance. (Also the Nuxt docs say it should be called index.js instead of store.js but maybe there is another way to set it up that I haven’t run into yet)Issue 2 is calling the
service
function outside of that createStore function and reusing the first instance on a subsequent call.Solution:
new Vuex.Store(...)
to acreateStore
function andexport default createStore
insteadconst servicePlugin = service(servicePath, {
to this:const servicePlugin = () => service(servicePath, {
modulePath => requireModule(modulePath).default
to this:modulePath => requireModule(modulePath).default()
const servicePlugins =
line into the createStore function that’s exported so the calls toservice
functions only happen during the execution ofcreateStore
I am green here so if any of this is problematic in some other way, please let me know.
Hope it helps!
In nuxt@3 classic vuex usage
new Vuex.Store
will be deprecated. There has to be another solution…