Skip to content

getStaticPaths doesn't work with 'publicRuntimeConfig' from next/config #11493

Discussion options

You must be logged in to vote

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:

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 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 the apiUrl into the page scripts so your code can use it.

Now you have a page that uses getStaticProps, this means tha…

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@diogotcorreia
Comment options

Comment options

You must be logged in to vote
1 reply
@paeolo
Comment options

Answer selected by diogotcorreia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
4 participants