question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read properties of undefined (reading 'getInitialProps')

See original GitHub issue

Verify 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

error

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:open
  • Created a year ago
  • Reactions:4
  • Comments:39 (12 by maintainers)

github_iconTop GitHub Comments

7reactions
kdy1commented, Apr 21, 2022

No, it’s a bug of swc minifier. As there are so many minification rules, there are some bugs. It’s a huge project.

image

I’ll add this to my private task list

7reactions
silentimcommented, Apr 19, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found