if (typeof window === 'undefined') {
}and add the server-side code in that block.
Similarly, you can execute client-side code only by checking
if (typeof window !== 'undefined') {
}Alternatively, the following can be used to determine _document.tsx just run on the server
if (!process.browser) {
console.log('This is running on the server.');
} else {
console.log('This is running in the browser.');
}