Next.js Discord

Discord Forum

publicRuntimeConfig and appDir

Answered
Gouty oak gall posted this in #help-forum
Open in Discord
Avatar
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
View full answer

11 Replies

Avatar
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
Gouty oak gallOP
Samer error:
Error: Cannot destructure property 'publicRuntimeConfig' of 'next_config__WEBPACK_IMPORTED_MODULE_1___default(...)(...)' as it is undefined.
Avatar
Rafael Almeida
are you trying to import it in a server component? it doesn't work there
Answer
Avatar
Rafael Almeida
hence why this is discouraged, it's a legacy feature
Avatar
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
Rafael Almeida
probably env vars
Avatar
Gouty oak gallOP
but those can also only be read on the server right?
Avatar
Rafael Almeida
if you prefix them with NEXT_PUBLIC_ they can be read from the client too
Avatar
Gouty oak gallOP
Thanks
Avatar
New Guinea Freshwater Crocodile
Thanks, spend almost an hour on this 😅