Cannot read properties of undefined (reading 'getInitialProps')
See original GitHub issueVerify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
next: 12.1.1-12.1.6-canary.2 react: 17.0.2 or 18.0.0 node: 14.19.1 system: windows
What browser are you using? (if relevant)
chrome 100.0.4896.88
How are you deploying your application? (if relevant)
next start
Describe the Bug
Expected Behavior
no error in console and display page content
To Reproduce
//app.ts
const MyApp = ({ Component, pageProps }: AppProps) => {
return <Component {...pageProps} />;
};
MyApp.getInitialProps = async (appContext: AppContext) => {
const some = await fetch('....');
const appProps = await App.getInitialProps(appContext);
return { ...appProps, pageProps: { ...appProps.pageProps, some } };
};
export default MyApp;
//index.ts
export default function Home(){
return (
<div>some text</div>
)
}
export const getStaticProps: GetStaticProps = async () => {
return { props: { } };
}
Then npm run build, everything is ok and built successfully. Now npm run start, get error like this in console (see image attached) and there is nothing displaying in browser, just blank:
A client-side exception has occurred, see here for more info: https://nextjs.org/docs/messages/client-side-exception-occurred Error rendering page: TypeError: Cannot read properties of undefined (reading ‘getInitialProps’)
No error if next 12.1.0 and more lower version.
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:39 (12 by maintainers)
Top Results From Across the Web
next js getInitialProps error Cannot read property 'map' of ...
I have been experiencing the same issue for past few days, from my experience what I think is that since there is a...
Read more >cannot read properties of undefined (reading 'getinitialprops ...
I am trying to run my headless Cypress tests on my Next.js React app via Github Actions. When I build and start my...
Read more >getInitialProps - Data Fetching - Next.js
getInitialProps receives a single argument called context , it's an object with the following properties: pathname - Current route. That is the path...
Read more >Nextjs Api: TypeError: Cannot read properties of undefined ...
... Cannot read properties of undefined (reading 'headers') ... AM: Setting up pages with getInitialProps as Netlify Functions in ...
Read more >TypeError: Cannot read property 'items' of undefined : r/nextjs
Hello everyone, I am having some trouble with this getInitialProps component Here is the code: import React from 'react'; import axios from ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No, it’s a bug of swc minifier. As there are so many minification rules, there are some bugs. It’s a huge project.
I’ll add this to my private task list
I found, if some function uses ‘zlib’ module in app.ts, and swcMinify=true in next.config.js, this error comes like above; If swcMinify=false, page is ok and no error. So then zlib will not be supported after next 12.1.0?