我已经四处寻找解决这个问题的办法了。他们都建议在你的tsconfig中添加"jsx": "react"。json文件。我已经做到了。另一个是添加“include:[]”,我也这样做过。然而,当我试图编辑.tsxfiles时,我仍然得到错误。下面是我的tsconfig文件。

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "allowJs": true,
        "checkJs": false,
        "jsx": "react",
        "outDir": "./build",
        "rootDir": "./lib",
        "removeComments": true,
        "noEmit": true,
        "pretty": true,
        "skipLibCheck": true,
        "strict": true,
        "moduleResolution": "node",
        "esModuleInterop": true
    },
    "include": [
        "./lib/**/*"
    ],
    "exclude": [
        "node_modules"
    ]
}

任何建议都会很有帮助。我使用babel 7编译所有的代码与env, react和typescript预设。如果你们需要更多的文件来帮助调试,请告诉我。


当前回答

2021年4月,这个问题仍然存在。我使用react-boilerplate-cra-template与react 17.02。

这是VSCode的一个问题,它默认使用内置的typescript。你只需要打开一个。tsx文件

按:Ctrl + Shift + P 输入:Typescript:选择Typescript版本… 选择:使用工作区版本。

其他回答

崇高文本的解决方案:

Make sure your package.json uses Typescript >= v4.1.2 Uninstall the Sublime Text "Typescript" package through Package Control At time of writing, it bundles Typescript v3.x Open a terminal in the Sublime Text "Packages" directory. cd "~/Library/Application Support/Sublime Text 3/Packages" Clone the Typescript-Sublime-Plugin repo into your Packages directory: git clone https://github.com/microsoft/TypeScript-Sublime-Plugin TypeScript Open User Settings: Sublime Text > Preferences > Settings Add "typescript_tsdk": "node_modules/typescript/lib" This tells the Sublime Typescript plugin to use the project version of Typescript rather than its bundled version. Restart Sublime Text Unlike most Sublime Text settings, this one requires a restart in order to restart the Typescript server.

参考: https://github.com/microsoft/TypeScript-Sublime-Plugin/issues/538

我的情况下,没有一个解决方案是有效的,所以我看了ECMA Scrypt版本。我的版本是ec5,你可以在这里检查-> tsconfig.json。所以我尝试将目标:“es5”切换为目标:“es2017”,它似乎可以处理这个问题,如果再次出现任何问题,我会编辑这条评论

在我的案例中,上述方法都不起作用。 我的问题是tsconfig的位置。Json不是项目根。 所以这个笑话不能读取。jsx文件。 我用符号链接tsconfig解出来了。Json到项目根目录。 也许有更好的解决办法。 如果你有的话告诉我。

对我来说,重新启动IDE就是解决办法。重新启动后,弹出一个消息框,显示我没有安装任何typescript,你想安装typescript 3.3吗? 我安装了它,现在它工作得很好。请看这里的输出窗口

添加"jsx": "react"到jsconfig。Json不适合我,但“jsx”:“preserve”做到了:

jsconfig。Json / tsconfig.json:

{
  "compilerOptions": {
    "jsx": "preserve"
  }
}