Cannot stringify POJOs with symbolic keys
See original GitHub issueWhen using Pinia from a fetch function in page with Nuxt, we get the following error for each Pinia store initiated.
WARN: Cannot stringify POJOs with symbolic keys Symbol(vfa.key.reactiveIdentifier)
It doesn’t seem to affect the functionality, but this seems to be something that shouldn’t happen…
Bug can be reproduced with a clean Nuxt installation:
npx create-nuxt-app piniabug
cd piniabug
yarn add pinia @vue/composition-api
# create a store according to example in Pinia README to stores/main.js
# setup the Nuxt plugin according to Pinia README
# setup composition-api as Nuxt plugin (see below)
# create a fetch function in the pages/index.vue file (see below)
plugins/composition-api.js
import Vue from 'vue';
import VueCompositionApi from '@vue/composition-api';
Vue.use(VueCompositionApi);
export * from '@vue/composition-api';
pages/index.vue (relevant parts)
import { useMainStore } from '@/stores/main'
...
fetch({ req }) {
const main = useMainStore(req);
console.log(main.state);
},
...
The error goes away if I use for example lodash cloneDeep on the req before passing it in to useMainStore, but that seems to break Pinia somehow, so that store modifications done during the fetch method are not available in the client-side.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Cannot stringify POJOs with symbolic keys #193 - vuejs/pinia
A decent fix without any additional dependencies seems to be to "clone" the object with JSON.stringify and JSON.parse before setting it to ...
Read more >Nuxt: All pages show a warning "Cannot stringify a function ...
Show activity on this post. To clarify, Nuxt serializes state from server to client i.e. it passes state from asyncData, data, vuex store...
Read more >Error when trying to do pagination with Nuxt and Firebase
I was trying to do pagination with firebase js sdk (v9) and nuxt 2 . When trying to read from firestore using the...
Read more >Using JavaScript Symbol.toStringTag for objects types ...
It is hard to determine if the object above is in certain type without checking the presence of all the properties, imagine if...
Read more >assets/app/stores.js - Renovate Bot Package Diff
throw new Error("Cannot stringify POJOs with symbolic keys");. 264. - }. 265. - Object.keys(thing).forEach(function (key) { return walk(thing[key]); });.
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
@posva thanks for this example. I figured out I got this error from somewhere else, perhaps by doing
console.error
on the server which caused nuxt-sentry trying to pass the error to the client and the error failed to serialize.I’m still getting the
cannot stringify pojos with symobolic keys
warning but it’s not breaking for me anymore. I might be passing something wrong to pinia state. I’ll create a new issue once I identify what state specifically causes it.This seems fixed: https://github.com/posva/pinia-example-nuxt. If you can reproduce in a boiled down reproduction with updated deps, open a new issue
It depends. If your state is serializable, you could also convert it to json instead. Take a look at the nuxt folder, it’s very easy to create a custom build module