Next.js - 是否可以调试 getServerSideProps?

Cri*_* E. 15 next.js

您好,根据文档getServerSideProps是一个仅在服务器端执行的函数。

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

因此,简单地删除调试器关键字是行不通的。

我努力了:

  • 在端口 9229 上附加 node.js 调试器
  • 跑步node --inspect-brk ./node_modules/next/dist/bin/next
  • 跑步cross-env NODE_OPTIONS='--inspect' next dev

console.log()debugger关键字似乎都没有任何效果。

然而,我来自 getServerSideProps 的道具被正确传递,这证明该函数被调用。

是否可以单步执行 getServerSideProps 或至少让 console.log 工作?谢谢!

聚苯乙烯

getServerSideProps 外部的代码行是可调试的并且可以按预期工作。

And*_*eng 6

为了使打开的调试端口正常打开,需要执行以下操作:

// 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",
Run Code Online (Sandbox Code Playgroud)

一旦调试端口是自己的,您应该能够使用您选择的检查器客户端。