getStaticPaths doesn't work with 'publicRuntimeConfig' from next/config #11493
-
When I add I get the following error: import getConfig from 'next/config';
const { publicRuntimeConfig } = getConfig(); After reading the documentation for Also, removing Does anyone have any idea what could be wrong or if this is a bug? I could look into migrating to env variables, but I'm not sure if they work on client-side (do they?). Edit: Since I've forgotten and it might be useful, here are my system details:
Edit 2: I've just tested with a new next app, it still happens. Here is a Gist that reproduces it: https://gist.github.com/diogotcorreia/64a15ea521f829a7552a5a6ec7888d28 Edit 3: This is expected behaviour: #12166 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
+1, just ran into this exact problem. |
Beta Was this translation helpful? Give feedback.
-
For anyone wondering, I've decided to move my config from A proper fix would still be appreciated. |
Beta Was this translation helpful? Give feedback.
-
Just run into the exactly same issue. |
Beta Was this translation helpful? Give feedback.
-
This is the expected behavior, The runtime config can be created in module.exports = {
publicRuntimeConfig: {
// Will be available on both server and client
apiUrl: process.env.API_URL,
},
} As you can see the config can be based on an environment variable, it could be loaded from a .env file or could be loaded from the system (like Now you have a page that uses So what happens if we build the app with This is why the docs states that the pages that use the
The static alternative to module.exports = {
env: {
apiUrl: process.env.API_URL,
},
} This value will be available both for static and server-rendered pages, but can only be changed with a new build. TL;DR: |
Beta Was this translation helpful? Give feedback.
This is the expected behavior,
publicRuntimeConfig
does not work with static pages, here is why:The runtime config can be created in
next.config.js
like this:As you can see the config can be based on an environment variable, it could be loaded from a .env file or could be loaded from the system (like
API_URL=prod.com yarn start
). The value of this config will be available in the server, so when a page is requested, the server will insert theapiUrl
into the page scripts so your code can use it.Now you have a page that uses
getStaticProps
, this means tha…