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
In Jest, you can simply mock this using this code.
jest.mock("next/config", () => () => ({
publicRuntimeConfig: {
contextPath: "",
},
}));
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With