Build: You cannot use JSX unless the -jsx flag is specified

I am using VS 2013 and tsx reaction files. I can create my project manually just fine. (Right click and create solution)

But when I try to publish to Azure, VS tries to build again, but at that time I get the whole bunch of errors, designated as:

Error 2 Build: Cannot use JSX unless the '--jsx' flag is provided. 

and points to my tsx files.

It seems that Azure Publish uses different build steps than VS 2013.

How can I fix this problem?

Azure Publish Error

VS 2013 Errors

+9
source share
6 answers

I added "jsx": "react" to my tsconfig.json to fix this error:

 { "compileOnSave": true, "compilerOptions": { "target": "es6", "outFile": "Content/app.js", "sourceMap": true, "jsx": "react" } } 
+11
source

Adding this to csproj worked for me in VS2015:

<PropertyGroup> <TypeScriptJSXEmit>react</TypeScriptJSXEmit> </PropertyGroup>

A source

+5
source

In your tsconfig.json add a jsx property with a reactive value of "jsx": "react" . Secondly, you must also include a file to display such compiler options (index.tsx).

 { "compilerOptions": { "outDir": "./build/", "sourceMap": true, "noImplicitAny": true, "module": "commonjs", "target": "es5", "jsx": "react" }, "files": [ "./src/app/index.tsx" ] } 
+3
source

If you still have to solve this problem, check your project settings, make sure to compile JSX in TSX files is set to React, and double check that you are looking at the correct assembly configuration (itโ€™s very easy to skip this and I have no idea why TS assembly is related to configuration configuration). Tested on VS2015.

EDIT . I should have mentioned that I was able to publish VS2015 before Azure; Initially, I ran into the same error and realized that my non-release configurations were updated, but not the release version. I made the change described above and posted it next.

+1
source

tsc --jsx helloWorld.tsx http://staxmanade.com/2015/08/playing-with-typescript-and-jsx/

You might be useful

0
source

The solution presented here worked for me in Visual Studio 2017

https://www.koskila.net/fixed-cannot-use-jsx-unless-the-jsx-flag-is-provided/

Mostly change TS Build properties.

Right-click on project-> Properties-> TypeScript Assembly.

In the JSX option to compile in TSX files, select React.

0
source

All Articles