我试图将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();
}
这是引发的错误。
我已经在我的tsconfig.json
中包含了"jsx": "react"
。我的配置如下:
{
"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"
]
}
1条答案
按热度按时间rsaldnfx1#
这解决了我的问题