2
votes

Hi as per docs getServerSideProps is a function which is executed only on server side.

export async function getServerSideProps(context) {
  console.log("hello world");
  debugger;
  return {
    props: {
      age:55
    }, // will be passed to the page component as props
  }
}

As a consequence simply dropping a debugger keyword won't work.

I have tried:

  • Attaching the node.js debugger on port 9229
  • Running node --inspect-brk ./node_modules/next/dist/bin/next
  • Running cross-env NODE_OPTIONS='--inspect' next dev

But neither console.log() nor debugger keyword seem to have any effect.

However my props from getServerSideProps are passed in correctly, which proves the function is called.

Is it possible to stepthrough getServerSideProps or at least get console.log working? Thanks!

P.S.

The lines of code outside getServerSideProps are debuggable and work as expected.

1

1 Answers

0
votes

In order to make the open the debug port open properly, you need to do the following:

// package.json scripts
"dev": "NODE_OPTIONS='--inspect' next dev"
// if you want custom debug port on a custom server
"dev": "NODE_OPTIONS='--inspect=5009' node server.js",

Once the debug port is own, you should be able to use inspector clients of your choice.