【问题标题】:Cannot use JSX unless the '--jsx' flag is provided when I did yarn start除非在我执行 yarn start 时提供了“--jsx”标志,否则无法使用 JSX
【发布时间】:2021-03-19 16:10:25
【问题描述】:

我做到了

  • 我做了 yarn start 并且 http://localhost:3000/ 成功了,但是有很多问题 已经出现

$yarn start 还有npm run start 纱线运行 v1.22.4 $ react-scripts 开始

The following changes are being made to your tsconfig.json file:
  - compilerOptions.jsx must be react-jsx (to support the new JSX transform in React 17)

i 「wds」: Project is running at http://192.168.56.1/
i 「wds」: webpack output is served from
i 「wds」: Content not from webpack is served from C:\Users\taiga\Github\Typescript\eslint-app\example\public
i 「wds」: 404s will fallback to /
Starting the development server...
Compiled successfully!

You can now view example in the browser.

  Local:            http://localhost:3000
  On Your Network:  http://192.168.56.1:3000

Note that the development build is not optimized.
To create a production build, use npm run build.

错误

  • Cannot use JSX unless the '--jsx' flag is provided

  • Module './App' was resolved to 'c:/Users/taiga/Github/Typescript/eslint-app/example/src/App.tsx', but '--jsx' is not set.

  • Argument for '--jsx' option must be: 'preserve', 'react-native', 'react'.

我试试

I tried this one

这是my repo

我的目标

  • 使用 lint a react-typescript-app

【问题讨论】:

    标签: typescript node-modules tsconfig react-typescript


    【解决方案1】:
    • 在使用 CRA(创建反应应用)初始化项目后,它是否可以正确编译/工作?

    可能是你更新过的包,用 CRA 初始化后尝试编译,不要更新任何包。 (https://github.com/taiga-programming/example-typescript/commit/b7074af02df6ce469b867a69625d5c1de7a209eb)

    但首先,您的提交 https://github.com/taiga-programming/example-typescript/commit/88ee7bfb164d9017883ea91535fadeb7e17691aa 中的 tsconfig.json 中有一些可疑之处:

       - "jsx": "react-jsx"
       + "jsx": "react"
    

    试着把"jsx": "react-jsx"放回去。

    【讨论】:

      【解决方案2】:

      这是 create-react-app (CRA) 脚本的一个未解决问题。唯一对我有用的解决方案是在.env 文件(在项目根目录中)中添加以下配置。

      DISABLE_NEW_JSX_TRANSFORM=true
      

      【讨论】:

        猜你喜欢
        • 2021-03-05
        • 2018-10-30
        • 2016-05-12
        • 2021-01-29
        • 2021-04-27
        • 2020-06-21
        • 2021-03-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多