Hi, @datehubin! Welcome to the Vercel Community
Thanks for sharing so much details on your error - helps us a lot! Let me try and help here.
The error “ReferenceError: document is not defined” typically occurs when you’re trying to access the document
object during server-side rendering or static generation. This is because the document
object is only available in the browser environment, not on the server.
To fix this, you need to ensure that any code accessing document
or other browser-specific APIs is only executed on the client-side. You can do this by:
- Using dynamic imports with
next/dynamic
for components that usedocument
. - Wrapping the code that uses
document
in auseEffect
hook or checking iftypeof window !== 'undefined'
before executing it.
When it comes to having differing local and Vercel environments, I recommend checking out this community post with some ideas on how to debug.
Remember, when deploying to Vercel, it’s crucial to ensure that your code is compatible with both client-side and server-side environments, especially when using Next.js with its server-side rendering capabilities.
Let us know how you get on!