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.

Cannot stringify POJOs with symbolic keys

See original GitHub issue

When 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:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MartinMalindacommented, Jul 7, 2021

@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.

0reactions
posvacommented, Jun 28, 2021

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

Would JSON.stringify really be a performance hit compared to what Nuxt is doing right now? But it makes sense if this needs to be fixed on Nuxt side primarily.

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

Read more comments on GitHub >

github_iconTop 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 >

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