typescript 构建:除非提供了“--jsx”标志,否则不能使用 JSX

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35169911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:14:59  来源:igfitidea点击:

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

azurevisual-studio-2013typescripttsx

提问by Teoman shipahi

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

我正在使用 VS 2013 和 tsx 文件进行反应。我可以手动构建我的项目就好了。(右键单击并构建解决方案)

But when I try to publish on Azure, VS tries to build again but at that time I am getting all bunch of errors stated as:

但是当我尝试在 Azure 上发布时,VS 尝试再次构建,但当时我收到了所有错误,如下所示:

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

and points to my tsx files.

并指向我的 tsx 文件。

Seems like Azure Publish using different kind of build steps than VS 2013 does.

似乎 Azure Publish 使用与 VS 2013 不同类型的构建步骤。

How can I fix this issue?

我该如何解决这个问题?

Azure publish error

Azure 发布错误

VS 2013 errors

VS 2013 错误

回答by Andy Edinborough

I added "jsx": "react"to my tsconfig.jsonto resolve this error:

我添加"jsx": "react"到我的tsconfig.json以解决此错误:

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

回答by theycallmemorty

Adding this to the csproj worked for me in VS2015:

在 VS2015 中将此添加到 csproj 对我有用:

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

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

Source

来源

回答by Juni Brosas

In your tsconfig.jsonadd a property jsx with react value "jsx": "react". Second, you should also include the file to reflect the compiler options like this (index.tsx).

在您tsconfig.json添加一个属性 jsx 与 react value "jsx": "react"。其次,您还应该包含文件以反映这样的编译器选项 (index.tsx)。

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

回答by Anshuman Goel

The solution provided here worked for me in Visual Studio 2017

此处提供的解决方案在 Visual Studio 2017 中对我有用

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

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

Basically changing TS Build properties.

基本上改变 TS Build 属性。

Right click on project->Properties->TypeScript Build

右键单击项目-> 属性-> TypeScript 构建

In option JSX compilation in TSX files choose React.

在 TSX 文件中的选项 JSX 编译中选择 React。

回答by Joe

If you happen to still be struggling with this, check your project settings, ensuring JSX compilation in TSX files is set to React, and double-check that you're looking at the correct build configuration (it's very easy to miss that, and I have no idea why TS build is build-configuration-specific). Tested on VS2015.

如果您碰巧仍然为此而苦苦挣扎,请检查您的项目设置,确保 TSX 文件中的 JSX 编译设置为 React,并仔细检查您正在查看正确的构建配置(很容易错过,我不知道为什么 TS build 是特定于构建配置的)。在 VS2015 上测试。

EDIT: I should have mentioned that I was able to publish from VS2015 to Azure; I originally came across this same error and realized that my non-release build configurations had been updated but not the release config. I made the change described above, and publish then succeeded.

编辑:我应该提到我能够从 VS2015 发布到 Azure;我最初遇到了同样的错误,并意识到我的非发布构建配置已更新,但未更新发布配置。我进行了上述更改,然后发布成功。

回答by danny

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

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

It might be helpful to you

可能对你有帮助