Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot destructure property publicRuntimeConfig of 'undefined' or 'null'. (v9.5.0) #15568

Open
stijnvanderlaan opened this issue Jul 28, 2020 · 14 comments
Labels
good first issue Easy to fix issues, good for newcomers
Milestone

Comments

@stijnvanderlaan
Copy link

stijnvanderlaan commented Jul 28, 2020

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
@stijnvanderlaan stijnvanderlaan changed the title Cannot destructure property publicRuntimeConfig of 'undefined' or 'null'. Cannot destructure property publicRuntimeConfig of 'undefined' or 'null'. (v9.5.0) Jul 28, 2020
@timneutkens timneutkens added good first issue Easy to fix issues, good for newcomers kind: bug labels Jul 28, 2020
@stijnvanderlaan
Copy link
Author

Looks like the results of runtime_config_default()() is undefined.
In another project the build works fine, but I can't find runtime_config_default inside .next.

@stijnvanderlaan
Copy link
Author

It seems to be related to lerna & different not being installed correctly, installing it in the root of the project with yarn add next -W fixed it for me.

@Timer Timer added this to the iteration 6 milestone Jul 29, 2020
@stijnvanderlaan
Copy link
Author

stijnvanderlaan commented Aug 3, 2020

I installed a package & this error is back, also in dev mode! Also tried 9.5.1.

@stijnvanderlaan
Copy link
Author

Oke, so I found the situation when this is happening. I use next-transpile-modules to import modules from a different component package. But when I try to call getConfig inside a component in a different package it fails, a workaround is passing the config to the Component.

@Timer Timer modified the milestones: iteration 6, backlog Aug 3, 2020
@ckeeney
Copy link

ckeeney commented Aug 13, 2020

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.

@kogai
Copy link

kogai commented Oct 12, 2020

I've got the same error too, when I've introduced getStaticProps.
it occurred when next dev subcommand executed, but the next build && next start did not the case.

Version of Next.js: 9.5.1

@talesmgodois
Copy link

I am geting this error in Next 9.5.5 under jest tests, just checking if my component isDefined

@nersoh
Copy link

nersoh commented Feb 23, 2021

I started to get this error when I updated from v10.0.6 to v10.0.7

@madeinspace
Copy link

I'm getting that error too I'm on v10.0.7 but had it since v9.5

@gushiguera
Copy link

Oke, so I found the situation when this is happening. I use next-transpile-modules to import modules from a different component package. But when I try to call getConfig inside a component in a different package it fails, a workaround is passing the config to the Component.

I also have next-transpile-modules in my next.config.js and running into this issue when running my tests? Any recommendations?

@jasonwilliams
Copy link

jasonwilliams commented Feb 23, 2022

I had this issue with npm workspaces. turns out i was calling next from the workspace node_modules and not the correct node_modules from the package folder. Basically I was calling the wrong version.

@alexmcode
Copy link

@gushiguera I have the same situation as you. What I did is mock it with jest.

@sebastianupr
Copy link

I solved this issue with this lines in jest.setup file:

import { setConfig } from 'next/config'
import config from './next.config'

setConfig(config)

@kvedantmahajan
Copy link

For those who encounter this running jest, here is a fix tested
In my case I was using

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

Changing the above to import { publicRuntimeConfig } from '<path/to>/next.config.js'; helped

@samcx samcx removed the kind: bug label Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

No branches or pull requests