Using TSX files with electronic compilation error
I am trying to compile my electronic program using an electronic compiler. React and typescript should be supported out of the box, however it throws a console error from React markup tags Uncaught SyntaxError: Unexpected token <
.
Is there a compiler option that should be used to support React syntax in TSX? When converted to JSX, it works fine.
source to share
Make sure you have .compilerc
at the root of your project and that you have defined the TypeScript compiler options for the text/typescript
MIME type . TypeScript compiler options must include an option "jsx": "react"
.
Here my .compilerc
:
{
"env": {
"development": {
"application/javascript": {
"presets": ["es2016-node5", "react"],
"sourceMaps": "inline"
},
"text/typescript":{
"target": "es6",
"module": "commonjs",
"sourceMap":true,
"inlineSourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"allowJs": true,
"jsx": "react"
}
},
"production": {
"application/javascript": {
"presets": ["es2016-node5", "react"],
"sourceMaps": "none"
},
"text/typescript":{
"target": "es6",
"module": "commonjs",
"sourceMap":false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"allowJs": true,
"jsx": "react"
}
}
}
}
source to share