I encountered a problem with my website that has a customized Document by _document.js. When I tried running yarn dev
, I received the error:
TypeError: Class constructor Document cannot be invoked without 'new'
I spent a considerable amount of time searching for solutions and went through multiple suggestions mentioning preset-env
within .babelrc
. However, I do not have any babel config file.
After some experimentation, changing
"target": "es5"
to "target": "es5"
resolved the issue. I prefer not to utilize es6
in my tsconfig.
What steps should I take next? (I am new to next.js
but well-versed in js
and react.js
)
UPDATE
Here is an excerpt from my _document.tsx
:
import Document, {
Html,
Head,
Main,
NextScript,
DocumentContext,
} from 'next/document'
import settings from '../utils/settings/settings'
class MyDocument extends Document {
render() {
return (
<Html lang="fa">
<!-- Code snippet omitted for brevity -->
</Html>
)
}
}
export default MyDocument
This is my tsconfig.json
:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}