Next.js Prerender错误“无法读取null的属性”

9udxz4iz  于 2023-08-04  发布在  其他
关注(0)|答案(1)|浏览(117)

我正在使用Next.js创建一个React应用程序(完整代码可以在here中找到)。
我碰到了一个很难调试的奇怪错误。当运行next build时,我得到以下错误,抱怨预渲染,我的五个页面中的每个页面都有一个错误:

spenc@WhiteBoxu:~/workout-tracker$ next build
info  - Loaded env from /home/spenc/workout-tracker/.env.local
info  - Linting and checking validity of types  
info  - Creating an optimized production build  
info  - Compiled successfully
info  - Collecting page data  
[    ] info  - Generating static pages (0/5)TypeError: Cannot read properties of null (reading 'useEffect')
    at exports.useEffect (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:24:292)
    at QueryClientProvider (file:///home/spenc/workout-tracker/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.mjs:46:9)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:479)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)

Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useEffect')
    at exports.useEffect (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:24:292)
    at QueryClientProvider (file:///home/spenc/workout-tracker/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.mjs:46:9)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:479)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
TypeError: Cannot read properties of null (reading 'useEffect')
    at exports.useEffect (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:24:292)
    at QueryClientProvider (file:///home/spenc/workout-tracker/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.mjs:46:9)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:479)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)

Error occurred prerendering page "/StartWorkoutPage". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useEffect')
    at exports.useEffect (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:24:292)
    at QueryClientProvider (file:///home/spenc/workout-tracker/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.mjs:46:9)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:479)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
TypeError: Cannot read properties of null (reading 'useEffect')
    at exports.useEffect (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:24:292)
    at QueryClientProvider (file:///home/spenc/workout-tracker/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.mjs:46:9)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:479)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)

Error occurred prerendering page "/ActiveWorkoutPage". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useEffect')
    at exports.useEffect (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:24:292)
    at QueryClientProvider (file:///home/spenc/workout-tracker/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.mjs:46:9)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:479)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
TypeError: Cannot read properties of null (reading 'useEffect')
    at exports.useEffect (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:24:292)
    at QueryClientProvider (file:///home/spenc/workout-tracker/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.mjs:46:9)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:479)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)

Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useEffect')
    at exports.useEffect (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:24:292)
    at QueryClientProvider (file:///home/spenc/workout-tracker/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.mjs:46:9)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:479)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
TypeError: Cannot read properties of null (reading 'useEffect')
    at exports.useEffect (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:24:292)
    at QueryClientProvider (file:///home/spenc/workout-tracker/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.mjs:46:9)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:479)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)

Error occurred prerendering page "/500". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useEffect')
    at exports.useEffect (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:24:292)
    at QueryClientProvider (file:///home/spenc/workout-tracker/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.mjs:46:9)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:479)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
info  - Generating static pages (5/5)

> Export encountered errors on following paths:
        /
        /ActiveWorkoutPage
        /StartWorkoutPage
        /_error: /404
        /_error: /500

字符串
我觉得奇怪的是
1.这在运行yarn build(仅Map到next build)时有效。

  1. yarn dev也可以工作(猜测本地开发没有预渲染,所以这是有意义的)
    1.它特别抱怨@tanstack/react-query中的QueryClientProvider,但如果我删除它并使_app.tsx直接返回<h1>foo</h1>,它反而会产生类似的错误:
spenc@WhiteBoxu:~/workout-tracker$ next build
info  - Loaded env from /home/spenc/workout-tracker/.env.local
info  - Linting and checking validity of types  
info  - Creating an optimized production build  
info  - Compiled successfully
info  - Collecting page data  
[    ] info  - Generating static pages (0/5)TypeError: Cannot read properties of null (reading 'useState')
    at exports.useState (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:25:394)
    at CreateWorkout (/home/spenc/workout-tracker/.next/server/pages/StartWorkoutPage.js:33:88)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
TypeError: Cannot read properties of null (reading 'useContext')
    at exports.useContext (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:24:118)
    at useRouter (/home/spenc/workout-tracker/.next/server/chunks/620.js:710:35)
    at WithRouterWrapper (/home/spenc/workout-tracker/.next/server/chunks/620.js:1108:43)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)

Error occurred prerendering page "/StartWorkoutPage". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useState')
    at exports.useState (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:25:394)
    at CreateWorkout (/home/spenc/workout-tracker/.next/server/pages/StartWorkoutPage.js:33:88)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
TypeError: Cannot read properties of null (reading 'useState')
    at exports.useState (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:25:394)
    at Steps (/home/spenc/workout-tracker/.next/server/pages/index.js:247:69)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)

Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useState')
    at exports.useState (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:25:394)
    at Steps (/home/spenc/workout-tracker/.next/server/pages/index.js:247:69)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)

Error occurred prerendering page "/ActiveWorkoutPage". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useContext')
    at exports.useContext (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:24:118)
    at useRouter (/home/spenc/workout-tracker/.next/server/chunks/620.js:710:35)
    at WithRouterWrapper (/home/spenc/workout-tracker/.next/server/chunks/620.js:1108:43)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
TypeError: Cannot read properties of null (reading 'useContext')
    at exports.useContext (/home/spenc/workout-tracker/node_modules/react/cjs/react.production.min.js:24:118)
    at Head (/home/spenc/workout-tracker/.next/server/pages/_error.js:283:44)
    at Wc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at $c (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at Zc (/home/spenc/.nvm/versions/node/v19.6.0/lib/node_modules/next/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:145)
...


以下是我的_app.tsx

import '@/styles/globals.css';

import type { AppProps } from 'next/app';

import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);

import BackgroundWaves from '@/components/shared/BackgroundWaves';

const queryClient = new QueryClient();

export default function App({ Component, pageProps }: AppProps) {
  return (
    <>
      <BackgroundWaves />
      <QueryClientProvider client={queryClient}>
        <Component {...pageProps} />
        <ReactQueryDevtools initialIsOpen={false} />
      </QueryClientProvider>
    </>
  );
}


和我的package.jsonscripts

"scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "heroku": "yarn build && heroku local",
    "check-types": "tsc --noemit",
    "lint": "npm run check-types && next lint"
  },


我检查了https://nextjs.org/docs/messages/prerender-error,但无法找到任何突出的
好像是基础设施的问题?有什么关于发生了什么和/或如何调试这样的东西的建议吗?

ufj5ltwl

ufj5ltwl1#

我只是经历了类似的事情,但它是与我的产品路线/product/[slug]。我将该目录移动到一个新的/pageStash目录,实际上只是在构建过程中隐藏了它。部署成功了。所以我“取消了”/products/[slug]目录(将其放回/pages/目录),构建工作正常。为什么??谁知道……。

相关问题