I have an error with web packs and nextjs.
import NextDocument, { Html, Head, Main, NextScript } from 'next/document'
import theme from '../libs/theme.js'
export default class Document extends NextDocument {
render() {
return (
<Html lang="en">
<Head />
<ColorModeScript initialColorMode={ theme.config.initialColorMode } />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}
Error: ReferenceError: Cannot access 'WEBPACK_DEFAULT_EXPORT' before initialization.
9 | <Head />
> 10 | <ColorModeScript initialColorMode={ theme.config.initialColorMode } />
| ^
11 | <body>
12 | <Main />
13 | <NextScript />
Does anyone know a fix? Thanks in advance!
As mentioned in the comments above try moving your script into the <body> (or into the <Head/>)
<Head />
<body>
<ColorModeScript initialColorMode={ theme.config.initialColorMode } />
</body>