TypeScript和React中“Cannot use JSX unless the '--jsx' flag is provided”错误
大家好!我是React和TypeScript的新手,正在尝试配置我的第一个项目。我使用TypeScript模板安装了create-react-app,但在编译时遇到错误:
```
Cannot use JSX unless the '--jsx' flag is provided.
```
我的App.tsx文件中的代码如下:
```tsx
import React from 'react';
const App: React.FC = () => {
return (
);
};
export default App;
```
我通过`npx create-react-app my-app --template typescript`创建了项目。文件夹中有tsconfig.json,但我没有查看过它。当我运行`npm start`时,一切正常,但如果我尝试通过`tsc`手动编译项目,就会遇到这个错误。
我还注意到,如果我将文件扩展名从.tsx改为.ts,错误就会消失,但那时JSX标签就无法工作了(React会报错)。
请告诉我哪里做错了?如何正确配置TypeScript以支持JSX?需要在tsconfig.json中修改什么吗?为什么create-react-app能正常工作,而手动tsc编译却不行?