Next Build (generating static page error)
Unanswered
cartar. posted this in #help-forum
cartar.OP
I've created 3 builds prior to this one and haven't really changed much other than some text on buttons and all of a sudden I'm being hit with this error:
It's happening on all of my routes, not sure what I've done for this to have happened.
Error occurred prerendering page "/servers". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useContext')It's happening on all of my routes, not sure what I've done for this to have happened.
36 Replies
@cartar. I've created 3 builds prior to this one and haven't really changed much other than some text on buttons and all of a sudden I'm being hit with this error:
Error occurred prerendering page "/servers". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useContext')
It's happening on all of my routes, not sure what I've done for this to have happened.
Can you give me a minimal reproduction repository?
cartar.OP
I can possibly in a little bit, but is it normal for this error to appear without even using contexts? @joulev
@cartar. I can possibly in a little bit, but is it normal for this error to appear without even using contexts? <@484037068239142956>
No it’s definitely not normal. But a different user also reported this issue yesterday (their production repository was super buggy so I couldn’t debug though), so I suspect this seems to be a nextjs bug
cartar.OP
Yeah, it just happened out of the blue.
That sucks
Do give me a reproduction repo though since I’ve been using canary for a very long time and never encountered this issue
cartar.OP
I'm not even using canary
I'm probably using an older version of nextjs because I'm picking up a project I haven't worked on in a while
Hmm then try upgrading nextjs first
cartar.OP
Would that cause any issues?
I'm using nextjs v13.0.3
Oh wow… then the issue is that your ui library or something like that uses context and you need to put use client
This is not a nextjs bug; a more recent nextjs version should give you a clearer error message
cartar.OP
I'm using a version of a UI library that is from around the time v13.0.3 was like the main version
Mantine, if you've ever heard of it
Follow this approach will likely help https://nextjs.org/docs/getting-started/react-essentials#third-party-packages
'use client'
import { Carousel } from 'acme-carousel'
export default Carouselcartar.OP
I'll try it out.
But do upgrade your nextjs version
Appdir has matured a lot since 13.0.3
cartar.OP
Alright.
Follow this issue too
It has everything you need to know about using mantime in appdir
I think
cartar.OP
Thanks.
cartar.OP
Hey, so I've updated Nextjs and I'm getting this error:
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. @joulevI've exported all of my functions / components
give me a minimal reproduction repository
cartar.OP
Nevermind, the error disappeared after I reloaded the application.
oh ic, well glad you fixed it
cartar.OP
@joulev I'm a little bit confused with how the new app directory works in conjuction with the pages directory.
I've seen people say using the app directory at the moment is optional.
However, I very much haven't implemented the new app directory and nothing in my pages directory is being rendered.
Any insight as to what could cause this? A switch I have to flip perhaps?
The issue is unrelated to this post, could you create a new post with a repro repo? Because the two routers can indeed work in conjunction with each other, the behaviour you described is weird