Next.js: Next config is undefined on dynamic pages using `getStaticProps`

Created on 24 Apr 2020  路  3Comments  路  Source: vercel/next.js

Bug report

Describe the bug

Hi,
On a dynamic routed page, I tried to migrate from getServerSideProps to getStaticPaths/getStaticProps to test SSG feature. But it does work. I get this error on page :

To Reproduce

TypeError: Cannot destructure property 'publicRuntimeConfig' of 'next_config__WEBPACK_IMPORTED_MODULE_3___default(...)(...)' as it is undefined.
    at getStaticPaths (/Users/jordid/GitHome/test-nextjs-config/.next/server/static/development/pages/todos/[id].js:174:5)
    at buildStaticPaths (/Users/jordid/GitHome/test-nextjs-config/node_modules/next/dist/build/utils.js:18:86)
    at Object.loadStaticPaths (/Users/jordid/GitHome/test-nextjs-config/node_modules/next/dist/server/static-paths-worker.js:8:140)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  type: 'TypeError'
}

Expected behavior

No error at runtime

System information

  • OS: macOS
  • Browser : all
  • Version of Next.js: 9.3.5
  • Version of Node.js: 12.16.1

Most helpful comment

Afaik you cannot use Runtime Configuration with static pages, from the docs:

A page that relies on publicRuntimeConfig must use getInitialProps to opt-out of Automatic Static Optimization. Runtime configuration won't be available to any page (or component in a page) without getInitialProps.

You can use the build-time env vars instead: https://nextjs.org/docs/api-reference/next.config.js/environment-variables

All 3 comments

Afaik you cannot use Runtime Configuration with static pages, from the docs:

A page that relies on publicRuntimeConfig must use getInitialProps to opt-out of Automatic Static Optimization. Runtime configuration won't be available to any page (or component in a page) without getInitialProps.

You can use the build-time env vars instead: https://nextjs.org/docs/api-reference/next.config.js/environment-variables

Yeah as @rafaelalmeidatk said it's documented that this is expected not to work for static pages as they don't run at runtime.

Ah ok I did not see it. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

havefive picture havefive  路  3Comments

olifante picture olifante  路  3Comments

formula349 picture formula349  路  3Comments

flybayer picture flybayer  路  3Comments