AMA*_*RMA 9 node.js express typescript reactjs
我试图将 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();
}
Run Code Online (Sandbox Code Playgroud)
这是抛出的错误。
我已经包含"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"
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1494 次 |
| 最近记录: |