Next.js: document is not defined

后端 未结 6 1710
一个人的身影
一个人的身影 2021-02-07 15:22

I am trying to create a payment form where people can pay but I keep getting this error.

document is not defined

I\'m using Next.js. Ple

6条回答
  •  故里飘歌
    2021-02-07 16:04

    You should read the difference between JS in node.js and JS in Browser. In node.js, you don't have DOM APIs (window, document, document.getElementById,...), the thing can be only have when your HTML is rendered in a thing called windows of Browsers. So next.js use node.js to run JS code and take result to render HTML file. But in node.js, nothing is windows of Browser.

    My English is quite bad. But I hope this answer will be helpful for you.

提交回复
热议问题