我刚刚安装了Next.js作为我的下一个网站的框架,但是在使用"next"进行主机托管时出现了以下错误:
TypeError: Cannot read properties of null (reading 'useContext')
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
Object.useContext
file:///C:/Users/sakura/Documents/hosting/node_modules/react/cjs/react.development.js (1618:21)
Html
..\..\AppData\Roaming\npm\node_modules\next\dist\pages\_document.js (685:105)
renderWithHooks
file:///C:/Users/sakura/AppData/Roaming/npm/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.development.js (5658:16)
renderIndeterminateComponent
file:///C:/Users/sakura/AppData/Roaming/npm/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.development.js (5731:15)
renderElement
file:///C:/Users/sakura/AppData/Roaming/npm/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.development.js (5946:7)
renderNodeDestructiveImpl
file:///C:/Users/sakura/AppData/Roaming/npm/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.development.js (6104:11)
renderNodeDestructive
file:///C:/Users/sakura/AppData/Roaming/npm/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.development.js (6076:14)
finishClassComponent
file:///C:/Users/sakura/AppData/Roaming/npm/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.development.js (5688:3)
renderClassComponent
file:///C:/Users/sakura/AppData/Roaming/npm/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.development.js (5696:3)
renderElement
file:///C:/Users/sakura/AppData/Roaming/npm/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.development.js (5943:7)
我不确定第一次编译这个网站是否通常会出现这种情况。也许是的。
我期望它编译网站,然后显示一个正常的网站,并且显示默认页面(就像React一样),但它返回了一个错误。
npm run dev
运行网站,它成功运行了。但是使用next dev
就不行。next build
命令也会出现错误。 - Teerasej