next.js: Cannot destructure property `publicRuntimeConfig` of 'undefined' or 'null'. (v9.5.0)
Bug report
After upgrading from 9.4.4 to 9.5.0 I get an error after building (in dev mode all works fine):
Cannot destructure property `publicRuntimeConfig` of 'undefined' or 'null'.
Code:
import getConfig from "next/config";
const { publicRuntimeConfig } = getConfig()
System information
- OS: macOS
- Browser: chrome
- Version of Next.js: 9.5.0
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 17
- Comments: 16 (2 by maintainers)
Commits related to this issue
- Fixes #15568 — committed to OmPrakashSahoo416/next.js by OmPrakashSahoo416 2 years ago
For those who encounter this running jest, here is a fix tested In my case I was using
Changing the above to
import { publicRuntimeConfig } from '<path/to>/next.config.js';helpedI solved this issue with this lines in jest.setup file:
I also have next-transpile-modules in my next.config.js and running into this issue when running my tests? Any recommendations?
I am geting this error in Next 9.5.5 under jest tests, just checking if my component isDefined
I’ve got the same error too, when I’ve introduced getStaticProps. it occurred when
next devsubcommand executed, but thenext build && next startdid not the case.Version of Next.js: 9.5.1
I encountered this same error when using yarn workspaces with one workspace depending on next 9.4 and another 9.5. updating next to the latest version in all workspaces resolved it for me.
It seems to be related to lerna & different not being installed correctly, installing it in the root of the project with
yarn add next -Wfixed it for me.