Я пытаюсь скомпилировать теги JSX в HTML, а затем сбросить их в файл HTML, но почему-то ts-node
не удается скомпилировать следующий фрагмент кода.
private index = (request: Request, response: Response) => {
// const component = React.createElement(Index, {key: 1, name: "Aman Sharma"}) // this works
const component = <Index key = {1} name = "Aman Sharma" /> // throws error
const html = ReactDOMServer.renderToString(component)
fs.writeFileSync('website/index.html', html);
response.status(200).send();
}
Это ошибка вылетает.
Я включил "jsx": "react"
в свой tsconfig.json
. Моя конфигурация выглядит следующим образом:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"es2015",
"dom"
],
"moduleResolution": "node",
"sourceMap": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"outDir": "build",
"jsx": "react",
"allowJs": true
},
"include": [
"src/**/*.{ts,tsx}"
],
"exclude": [
"node_modules"
]
}
Это решило проблему для меня
"jsx": "react-jsx",