Complex runtimeConfig values become `{}` inside the app
See original GitHub issueEnvironment
Nuxi 3.0.0-rc.12 14:16:13
RootDir: /home/projects/nuxt-runtimeconfig-complex-objects 14:16:14
Nuxt project info: 14:16:14
------------------------------
- Operating System: `Linux`
- Node Version: `v16.14.2`
- Nuxt Version: `3.0.0-rc.12`
- Nitro Version: `0.6.0`
- Package Manager: `npm@7.17.0`
- Builder: `vite`
- User Config: `runtimeConfig`
- Runtime Modules: `-`
- Build Modules: `-`
------------------------------
Reproduction
https://stackblitz.com/edit/nuxt-runtimeconfig-complex-objects?file=nuxt.config.ts,app.vue
Describe the bug
When passing a complex object into the runtime config it comes out as an empty object ({}
) on the other side.
- When passing in:
import redisDriver from 'unstorage/drivers/redis';
const driver = redisDriver();
console.log('driver should be: ', driver);
export default defineNuxtConfig({
runtimeConfig: {
driver,
},
});
we get:
driver should be: { 14:18:56
hasItem: [Function: hasItem],
getItem: [Function: getItem],
setItem: [Function: setItem],
removeItem: [Function: removeItem],
getKeys: [Function: getKeys],
clear: [AsyncFunction: clear],
dispose: [Function: dispose]
}
- And then inspecting
driver
inside theapp.vue
:
<template>
<div>Checkout the console.logs</div>
</template>
<script setup lang="ts">
if (process.server) {
const config = useRuntimeConfig();
console.log('driver is: ', config.driver);
}
</script>
we get:
driver is: {}
Here, I’d expect driver is: ...
to say the same thing as driver should be: ...
Additional context
This first arose in this nuxt-session
PR by @Twitch0125. I could imagine that this is due to some de-/serialization happening. I checked the current runtime config docs and couldn’t find anything about this happening. If some de-/serialization prevents us from using non-primitive config values, I have some ideas for improvements:
- document it in the runtime config docs
- use typescript to disallow config values that will not make it through “whole”
Thanks ❤️
Logs
No response
Issue Analytics
- State:
- Created a year ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Deep-dive into .NET Core primitives, part 3: runtimeconfig.json ...
The file can be used to control settings which are not surfaced in Visual Studio, such as automatically running your app on higher...
Read more >asp.net - Appropriate content for Myapp..runtimeconfig.json ...
1 (according nuget) with no problem. I am unable to figure the good values to set in this file to host a MVC...
Read more >runtimeconfig.json contains incorrect framework version #686
Currently, a package reference to Microsoft.NETCore.App 1.0.3 produces runtimeconfig with 1.0.0, but should be 1.0.3. visibility in NuGet GUI in ...
Read more >.NET Runtime config options - .NET | Microsoft Learn
Configuring an option in the runtimeconfig.json or project file applies the setting to that application only. Some configuration values can ...
Read more >Providing Runtime configuration to an Angular Application
First of all, you will need to create a config file in JSON format under assets/ folder (we don't want this file to...
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 Free
Top 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
We don’t really want users to pass non-serialisable data from
nuxt.config
to the runtime part of the app as it blurs the boundary between configuration and runtime code.As a module author, you can inject the nitro plugin yourself based on the user’s configuration of your module. (Or do various other things depending on your use case.) It’s difficult to say in the abstract, but feel free to drop me a line and I’ll happily assist.
@BracketJohn we also have a Nuxt integration for next still in private because of some upcoming Request/Response changes. And yes, we did not go with passing config via
nuxt.config
because of serialization.If you are interested in brining this into our monorepo, you can message https://twitter.com/balazsorban44
@danielroe is there any nitro plugin example related to this?