.tsx webpack compile fails: Unexpected token <

后端 未结 1 1413
囚心锁ツ
囚心锁ツ 2021-01-12 18:13

My app compiles with .ts, .js, and .jsx files and runs. Now I try changing a .jsx file to .tsx and it breaks.

How do I fix this compile error:

ts-lo         


        
相关标签:
1条回答
  • 2021-01-12 18:44

    The first issue has to do with "jsx" config as mentioned by Martin. Set "jsx" to "react".

    The second issue has to do with your code. Change it like this:

    class DiviAppBar extends React.Component<Props, State> ...
    

    Create an interface for your props and another one for your state. If you don't have any use empty objects.

    class DiviAppBar extends React.Component<{}, {}> ...
    
    0 讨论(0)
提交回复
热议问题