publicRuntimeConfig and appDir
Answered
Gouty oak gall posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Gouty oak gallOP
I am trying to use publicRuntimeConfig throughout my new appDir based app. I'm getting an error about deconstructing
getConfig()
. Based on the help I think this may be because my app is trying to statically render. If my page doesn't require a fetch but does want to use getConfig
what is the recommendation?Answered by Rafael Almeida
are you trying to import it in a server component? it doesn't work there
11 Replies
![Avatar](https://cdn.discordapp.com/guilds/752553802359505017/users/258390283127881728/avatars/6d84d27ad734d86c3c3d7f004660bded.webp?size=256)
Rafael Almeida
try to change the route segment config to
dynamic = 'force-dynamic'
: https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Gouty oak gallOP
Samer error:
Error: Cannot destructure property 'publicRuntimeConfig' of 'next_config__WEBPACK_IMPORTED_MODULE_1___default(...)(...)' as it is undefined.
![Avatar](https://cdn.discordapp.com/guilds/752553802359505017/users/258390283127881728/avatars/6d84d27ad734d86c3c3d7f004660bded.webp?size=256)
Rafael Almeida
are you trying to import it in a server component? it doesn't work there
Answer
![Avatar](https://cdn.discordapp.com/guilds/752553802359505017/users/258390283127881728/avatars/6d84d27ad734d86c3c3d7f004660bded.webp?size=256)
Rafael Almeida
hence why this is discouraged, it's a legacy feature
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Gouty oak gallOP
What would be the preferred way to have configuration (things you want to parameterize for the app but have available everywhere?)
![Avatar](https://cdn.discordapp.com/guilds/752553802359505017/users/258390283127881728/avatars/6d84d27ad734d86c3c3d7f004660bded.webp?size=256)
Rafael Almeida
probably env vars
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Gouty oak gallOP
but those can also only be read on the server right?
![Avatar](https://cdn.discordapp.com/guilds/752553802359505017/users/258390283127881728/avatars/6d84d27ad734d86c3c3d7f004660bded.webp?size=256)
Rafael Almeida
if you prefix them with
NEXT_PUBLIC_
they can be read from the client too![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Gouty oak gallOP
Thanks
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
New Guinea Freshwater Crocodile
Thanks, spend almost an hour on this 😅