Skip to content
DocsErrors`getInitialProps` was defined as an instance method

`getInitialProps` was defined as an instance method

Why This Error Occurred

getInitialProps must be a static method in order to be called by next.js.

Possible Ways to Fix It

Use the static keyword.

pages/example.js
export default class YourEntryComponent extends React.Component {
  static getInitialProps() {
    return {}
  }
 
  render() {
    return 'foo'
  }
}

or

pages/example.js
const YourEntryComponent = function () {
  return 'foo'
}
 
YourEntryComponent.getInitialProps = () => {
  return {}
}
 
export default YourEntryComponent