'Custom app: unhandledRejection: TypeError: Cannot read properties of undefined (reading 'prototype')
I'm using getInitialProps in my _app.js:
import App from "next/app";
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />;
}
MyApp.getInitialProps = async ({ Component, ctx }) => {
const appContext = App.getInitialProps(ctx);
let pageProps = {};
if (Component.getInitialProps)
pageProps = await Component.getInitialProps(ctx);
return { pageProps };
};
export default MyApp;
But getting the error
unhandledRejection: TypeError: Cannot read properties of undefined (reading 'prototype')
The app still compiles successfully and the error is shown inside the terminal. To reproduce it, you would only need to create a new nextjs app, and add the getInitialProps function
Solution 1:[1]
I didn't follow the docs, the problem was with the destructuring I did, you need to receive the whole context object for App.getInitialProps
MyApp.getInitialProps = async (context) => {
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sir-haver |
