Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Next.js Cannot destructure property 'publicRuntimeConfig' of '(0 , config_1.default)(...)' as it is undefined

import getConfig from 'next/config';
  
const { publicRuntimeConfig } = getConfig();

getConfig always returns undefined after updating from Next 10.0.7 to 10.0.8 or any other version above. But everything works with any other version below 10.0.8

like image 837
Anton Avatar asked Dec 18 '25 05:12

Anton


2 Answers

In Jest, you can simply mock this using this code.

jest.mock("next/config", () => () => ({
  publicRuntimeConfig: {
    contextPath: "",
  },
}));
like image 165
Knight Rider Avatar answered Dec 19 '25 19:12

Knight Rider


According to the docs the feature is deprecated.

This feature is deprecated. We recommend using environment variables instead, which also can support reading runtime values.

You can use an environment variable with the prefix NEXT_PUBLIC_ and simply use process.env.NEXT_PUBLIC_MY_VARIABLE wherever you need it in the code.

like image 38
lighthaus205 Avatar answered Dec 19 '25 17:12

lighthaus205



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!