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

disallow non-JSON-serialisable types in options.runtimeConfig #13992

Open
msdsk opened this issue May 18, 2022 · 3 comments
Open

disallow non-JSON-serialisable types in options.runtimeConfig #13992

msdsk opened this issue May 18, 2022 · 3 comments

Comments

@msdsk
Copy link

msdsk commented May 18, 2022

Environment

  • Operating System: Linux
  • Node Version: v17.2.0
  • Nuxt Version: 3.0.0-rc.3
  • Package Manager: npm@8.1.4
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

in nuxt.config.ts add:

...
  runtimeConfig: {
    public: {
      someMap: new Map()
    }
  },
...

Describe the bug

The map is transformed into an empty object (regardless if the map was empty or not) instead of being passed to the browser as-is.

Additional context

The expected behavior was working in rc1

Logs

No response

@wobsoriano
Copy link
Member

This feature would really be great. I think module options don't accept Map as well.

@danielroe
Copy link
Member

Runtime config set in Nuxt config needs to be serialisable. Map is not a valid type for it, and no matter what, won't be passed directly to the browser. It's possible we could accept Map as a type for it in nuxt.config but I think the benefit is very slight, when you could simply do:

runtimeConfig: Object.fromEntries(config.entries())

@danielroe danielroe added the discussion label Sep 20, 2022 — with Volta.net
@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
@danielroe
Copy link
Member

danielroe commented Mar 6, 2023

We might be able to do some interesting things with serialising different data types between server -> client (e.g. #12831, #19205) but I think that we should not support them between nuxt.config -> build. Rather, we should update the types for runtimeConfig and appConfig input in nuxt.config to disallow non-JSON-serialisable types from being set as an early-warning flag for users.

@danielroe danielroe added the dx label Mar 6, 2023
@danielroe danielroe changed the title Passing a map as a runtimeConfig entry disallow non-JSON-serialisable types in options.runtimeConfig Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants