publicRuntimeConfig and appDir
Answered
Gouty oak gall posted this in #help-forum
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
try to change the route segment config to
dynamic = 'force-dynamic'
: https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicGouty oak gallOP
Samer error:
Error: Cannot destructure property 'publicRuntimeConfig' of 'next_config__WEBPACK_IMPORTED_MODULE_1___default(...)(...)' as it is undefined.
are you trying to import it in a server component? it doesn't work there
Answer
hence why this is discouraged, it's a legacy feature
Gouty oak gallOP
What would be the preferred way to have configuration (things you want to parameterize for the app but have available everywhere?)
probably env vars
Gouty oak gallOP
but those can also only be read on the server right?
if you prefix them with
NEXT_PUBLIC_
they can be read from the client tooGouty oak gallOP
Thanks
New Guinea Freshwater Crocodile
Thanks, spend almost an hour on this 😅