Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot stringify arbitrary non-POJOs" error in Nuxt projects #382

Open
robregonm opened this issue Mar 29, 2024 · 2 comments
Open

"Cannot stringify arbitrary non-POJOs" error in Nuxt projects #382

robregonm opened this issue Mar 29, 2024 · 2 comments

Comments

@robregonm
Copy link

API Platform version(s) affected: 3.2.18

Description
Clients generated for Nuxt will fail with: "Cannot stringify arbitrary non-POJOs"

How to reproduce

  • Create an Entity e.g. "Animal"
  • Create a Nuxt project
  • Create a client (e.g. yarn create @api-platform/client https://localhost/ . --generator nuxt --resource animal )
  • Load https://localhost/animal
    You'll get a message saying: "Cannot stringify arbitrary non-POJOs"

Possible Solution

  • One solution is to edit nuxt.config.js and add the following:
  experimental: {
    renderJsonPayloads: false,
  },
  • Another possible solution is to edit ./nuxt/stores/animal/list.ts and add shallowRef() to setHubUrl function:
setHubUrl(hubUrl?: URL) {
      this.hubUrl = shallowRef(hubUrl);
    },
  • Another solution is to edit ./composables/api.ts and add shallowRef() to all onResponse()` functions.

Additional Context
This is occurring with all projects using Nuxt 3.4 or later.
More info at: https://nuxt.com/blog/v3-4#payload-enhancements

@J3m5
Copy link

J3m5 commented Mar 29, 2024

Hello @robregonm
I think we could just store the URL as a string and not as a URL object, what do you think?

@robregonm
Copy link
Author

robregonm commented Mar 29, 2024

@J3m5 That's another good and simple workaround. Agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants