GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Error when using new 'react-jsx' TypeScript transform · Issue #10144 · react/create-react-app

Error when using new 'react-jsx' TypeScript transform #10144

New issue
Copy link
New issue
Copy link
Closed
Closed
Error when using new 'react-jsx' TypeScript transform#10144
Copy link
Labels
issue: bug reportneeds triage

Description

@dcsan
dcsan
opened on Nov 24, 2020
Issue body actions

Describe the bug

start a vanilla project using the typescript template
open any file. you'll see an error like this this:

image

try to edit the tsconfig.json
image

but CRA overwrites the file every time it starts. Many bug reports on this ducking behavior

  • tsconfig.json gets overwritten preventing real configuration #8614
  • https://stackoverflow.com/questions/53794875/how-to-configure-react-script-so-that-it-doesnt-override-tsconfig-json-on-star

etc.

Did you try recovering your dependencies?

yes

Which terms did you search for in User Guide?

wtf does cra overwrite my tsconfig.json

Cannot use JSX unless the '--jsx' flag is provided.",

Environment

➜  tadmin git:(tadmin) ✗ npx create-react-app --info
npx: installed 67 in 4.641s

Environment Info:

  current version of create-react-app: 4.0.1
  running from /Users/dc/.npm/_npx/17244/lib/node_modules/create-react-app

  System:
    OS: macOS 10.15.7
    CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
  Binaries:
    Node: 14.5.0 - /usr/local/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.14.9 - /usr/local/bin/npm
  Browsers:
    Chrome: 86.0.4240.198
    Edge: Not Found
    Firefox: Not Found
    Safari: 14.0.1
  npmPackages:
    react: ^17.0.1 => 17.0.1
    react-dom: ^17.0.1 => 17.0.1
    react-scripts: 4.0.1 => 4.0.1
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

1 $ npx create-react-app my-app --template typescript
2 open vscode editor.

Expected behavior

can use typescript with CRA

Actual behavior

FFS
image

Reproducible demo

try with your own template

Reacted by Matthias, Anurag Hazra, Kian Zhu, nph, Gunn, pengfei, Matt H, Alex Fox Gill, Soichiro Miki, Pavel and 10 more
Reacted by Alex LeBron and Juan Rebella
Reacted by Alex LeBron and isaacgalvan671-web

Activity

Next
  1. dcsan
    added
    issue: bug report
    needs triage
    on Nov 24, 2020
  2. dcsan commented on Nov 24, 2020

    @dcsan
    dcsan
    on Nov 24, 2020
    Author
    More actions

    the --jsx bug is all over too

    https://stackoverflow.com/questions/50432556/cannot-use-jsx-unless-the-jsx-flag-is-provided

    I guess craco isn't working with CRA4 (yet?)
    so the only way to use TS with CRA(4) seems to be to eject right now.

  3. rafgraph commented on Nov 24, 2020

    @rafgraph
    rafgraph
    on Nov 24, 2020
    Contributor
    More actions

    This is because VS Code the app hasn't updated to typescript v4.1 yet which has support for the new jsx transform. To fix this you need to tell VS Code to use the Workspace version of typescript (v4.1.2).

    EDIT: while this works, there is a simpler solution (see below)
    To fix this, while viewing a TS file, bring up the command pallet (cmd+shift+p) and type "select typescript version", select the option and then select "Use Workspace Version 4.1.2".

    Side note, while CRA creates a package.json with "typescript": "^4.0.3", the actual installed version in node_modules is 4.1.2 (this should be fix by CRA as 4.0.3 is not compatible). So it probably makes sense to also update the typescript version in package.json.

    Simpler solution:
    If you just update the TS version in package.json to 4.1.2, VS Code will automatically use the workspace version because it knows its internal TS version is not compatible with the project. This way you don't end up with a .vscode/settings.json in your project.

    As @asterikx pointed out, update package.json to:

    "react-scripts": "^4.0.1",
    "typescript": "^4.1.2"
    
    Reacted by _, Andrei L, 심학준, Sergey Makarov, DangoPlus, Chloe, alanuuu, Dan Morgan, Pablo Vinícius, Noah Burroughs and 45 more
    Reacted by DangoPlus, Robbie Cook, Matthias, Jing Yi Wang, joachim zeelmaekers, DarrenDanielDay, erich0123 and Thanos Karagiannis
    Reacted by Joshua, Robbie Cook, hasheranto, Matthias, Jing Yi Wang, Aseer KT, joachim zeelmaekers, Bill, ThePigStupo, Thanos Karagiannis and 1 more
    Reacted by Samrat Saha and Thanos Karagiannis
  4. asterikx commented on Nov 25, 2020

    @asterikx
    asterikx
    on Nov 25, 2020
    More actions

    For me, it works after upgrading to "react-scripts": "^4.0.1":

    "react-scripts": "^4.0.1",
    "typescript": "^4.1.2"
    Reacted by JivkoJelev91, BlockC, FarihaAftab0, Juan Rebella and shreyansh-error-89
  5. ianschmitz commented on Nov 25, 2020

    @ianschmitz
    ianschmitz
    on Nov 25, 2020
    Contributor
    More actions

    This is an editor issue, and not specific to CRA from what i can tell. If you receive errors in npm start or npm run build, then you know you have an issue with CRA. The suggestion from #10144 (comment) should get you on the right path.

    Reacted by Andrei L
  6. ianschmitz
    closed this as completedon Nov 25, 2020
  7. ianschmitz
    changed the title [-]CRA 4.0 doesn't function with typescript[/-] [+]Error when using new 'react-jsx' TypeScript transform[/+] on Nov 25, 2020
  8. ianschmitz
    pinned this issue on Nov 25, 2020
  9. dcsan commented on Nov 25, 2020

    @dcsan
    dcsan
    on Nov 25, 2020
    Author
    More actions

    @rafgraph thanks for the helpful tip! I can confirm the steps above fixed this.

    VSCode also creates a project .vscode/settings.json file to control this setting, it might be useful to copy this into the repo when doing the setup, if it is a vscode specific setting.

    {
      "typescript.tsdk": "node_modules/typescript/lib"
    }
    Reacted by Lucas Fontinele, meleu, Pablo Vinícius, Long Nguyen, Acid Coder, Tai, joachim zeelmaekers, Nguyen Anh Tan and Meng Jia
    Reacted by meleu, Pablo Vinícius, Aurélien Dupays Dexemple, Tai, joachim zeelmaekers and Amir Mohammad Moradi
  10. steviss
    added a commit that references this issue on Dec 1, 2020

    https://code.visualstudio.com/docs/typescript/typescript-compiling#_u…

    6ee3877
  11. Robbie-Cook commented on Dec 3, 2020

    @Robbie-Cook
    Robbie-Cook
    on Dec 3, 2020
    More actions

    God bless you @rafgraph

  12. sromocki commented on Dec 4, 2020

    @sromocki
    sromocki
    on Dec 4, 2020
    More actions

    I have
    "react-scripts": "^4.0.1", "typescript": "^4.1.2"

    Doing a react-scripts build changes my "jsx": "react" to "jsx": "react-jsx", failing the build.

    Reacted by Marius, John Garcia, Vincent Taverna, Noah Kettler, mcbelthasar, JivkoJelev91, Samu Tamminen, Isaac Donoghue, paddotk, Sahil Chimnani and 1 more
    Reacted by Pablo Novas and Cake
  13. eai04191
    added a commit that references this issue on Dec 5, 2020

    Upgrade typescript to force the version used for VS Code

    997dad6
  14. navin-moorthy
    added a commit that references this issue on Dec 7, 2020

    refactor(src): ♻️ remove extra boilerplates

    5a8989f
  15. 9 remaining items

  16. chrisbu commented on Jan 25, 2021

    @chrisbu
    chrisbu
    on Jan 25, 2021
    More actions

    @Cidrax this answer on SO worked for me with intellij based IDEs - https://stackoverflow.com/a/65090491

    In IDE settings:

    ticking "Always download the most recent version of schemas" in Remote JSON Schemas.

    Reacted by willks, Mike Odom, Thomas Rooney, Taven Shumaker, Denys Pavlenko and Denis Ivanov
  17. bineetNaidu commented on Jan 27, 2021

    @bineetNaidu
    bineetNaidu
    on Jan 27, 2021
    More actions

    Maybe your VS code is using built-in TS version. The problem i had is similar to this. view here

  18. mattcarpowich1 commented on Jan 31, 2021

    @mattcarpowich1
    mattcarpowich1
    on Jan 31, 2021
    More actions

    maybe not recommended, but I updated the node_modules file directly.

    node_modules > react-scripts > scripts > utils > verifyTypeScriptSetup.js

    changed around line 154:

    hasJsxRuntime && semver.gte(ts.version, '4.1.0-beta') ? 'react' : 'react',

    Reacted by Erik Müller, Sedat and paddotk
  19. bineetNaidu commented on Jan 31, 2021

    @bineetNaidu
    bineetNaidu
    on Jan 31, 2021
    More actions

    Not The Best Way to solve this but surely something to look on 🤔 🤔 🤔

  20. iwosz commented on Mar 16, 2021

    @iwosz
    iwosz
    on Mar 16, 2021
    More actions

    For the record, I have the same error with TS version 4.2.3

    OS: Windows 10
    VS Code: 1.54.3

    package.json:

    "react": "^17.0.1",
    "typescript": "^4.2.3",
    "react-scripts": "4.0.3"

    tsconfig.json:

    "module": "esnext",
    "moduleResolution": "node",
    "jsx": "react-jsx",
    ...
    "include": [
        "src",
        "./src/**/*.tsx"
    ]

    .vscode/settings.json:

    "typescript.tsdk": "node_modules\\typescript\\lib"

    VS Code -> Use Workspace Version -> 4.2.3

    And I still get:

    Error: Cannot use JSX unless the '--jsx' flag is provided. ts(17004)

    Restart VS Code or reopen project folder won't fix the problem. The error is related to a new version of React because when I change to "jsx": "react" the error disappears in VS Code. As You know CRA after build overrides tsconfig to original version "jsx": "react-jsx" 🙂 so my question is simple:

    Is there any official fix for this problem in VS Code with TypeScript version ^4.3.2 and React version ^17?

    Reacted by JivkoJelev91, Josep Jaume Rey, Max Naegele, Nathaniel (Nate) Ram, Chris Holt, pol, Jeffry Angtoni, blackbell, Luiz Amorim, George Yong and 1 more
  21. JivkoJelev91 commented on Mar 31, 2021

    @JivkoJelev91
    JivkoJelev91
    on Mar 31, 2021
    More actions

    Any luck figuring it out?

    Reacted by Andres Alcocer , Nathaniel (Nate) Ram, B.Alexander, Chris Holt, pol and dolphrundgren
  22. holtc commented on May 11, 2021

    @holtc
    holtc
    on May 11, 2021
    More actions

    Is there any update on this?

    Reacted by pol, George Yong, dolphrundgren and Ole Frank Jensen
  23. geoyws commented on Jun 16, 2021

    @geoyws
    geoyws
    on Jun 16, 2021
    More actions

    For those using Yarn Workspaces, you'll have to nohoist or resolutions your typescript via your package.json. It works for me now.

    {
      "name": "root",
      "version": "1.0.0",
      "private": true,
      "repository": "https://gitlab.com/foo-product/foo-root.git",
      "license": "MIT",
      "author": "Foo Bar <[email protected]>",
      "main": "index.js",
      "workspaces": {
        "packages": [
          "packages/*"
        ],
        "nohoist": [
          "**/babel**",
          "**/eslint**",
          "**/jest**",
          "**/webpack**",
          "**/type-graphql**"
        ]
      },
      "scripts": {
        "postInstall": "lerna bootstrap"
      },
      "resolutions": {
        "graphql": "^15.3.0",
        "typescript": "^4.3.2"
      }
    }
    Reacted by Archimedes Trajano
  24. paddotk commented on Jun 24, 2021

    @paddotk
    paddotk
    on Jun 24, 2021
    More actions

    June 2021 and the problem still persists. I can't develop any React app at all because of this, and I don't see why CRA has to meddle with these configurations in the first place. PS I use Atom as my editor which does not add any own config file.
    I tried updating typescript and react-scripts to those specific suggested versions, but alas...

    Reacted by Timophey Molchanov, Daniil Tsioma, Sergio Morlan Paramo, Matty Ames and Sahil Chimnani
  25. sasweb commented on Jul 13, 2021

    @sasweb
    sasweb
    on Jul 13, 2021
    More actions

    For me

    "include": [
      "./src/**/*.ts*"
    ]
    

    together with TS version >= 4.1.2 in package.json did the trick.

    I guess just "./src/**/*.tsx" won't work when you have .ts files in your project (cc: @iwosz).

  26. geni94 commented on Jul 14, 2021

    @geni94
    geni94
    on Jul 14, 2021
    More actions

    The interesting bit of this issue, is that the .tsx components load just fine. However, VSCode and WebStorm will throw an error when you add the file format, and will also throw another error when removing the .tsx format.

    I fell on this error while adding TypeScript to an already-created React app [with create-react-app]. I am not sure if it wouldn't be an issue if you're building it with other tools/have complete control on Webpack resolvers and loaders, since as I mentioned, the app doesn't crash and the files are loaded and transpiled correctly.

    Hope this helps somehow.

  27. johankson commented on Mar 20, 2022

    @johankson
    johankson
    on Mar 20, 2022
    More actions

    @rafgraph thanks for the helpful tip! I can confirm the steps above fixed this.

    VSCode also creates a project .vscode/settings.json file to control this setting, it might be useful to copy this into the repo when doing the setup, if it is a vscode specific setting.

    {
      "typescript.tsdk": "node_modules/typescript/lib"
    }

    This worked for me when the issue was that it compiled fine on npm start but when saving it failed (at recompile) with discussed issue.

    Just adding this comment in case someone else ends up in the same rabbit hole!

    My package.json for reference

         "react-scripts": "5.0.0",
          "typescript": "^4.6.2",
    
  28. ali55ahmad6677 commented on Apr 11, 2025

    @ali55ahmad6677
    ali55ahmad6677
    on Apr 11, 2025
    More actions

    #10144

  29. Huaian666 commented on Jun 18, 2026

    @Huaian666
    Huaian666
    on Jun 18, 2026
    More actions

    this one had me stuck for a good hour. clearing cache + restart fixed it temporarily but it comes back

  30. Mulesneha commented on Nov 16, 2026

    @Mulesneha
    Mulesneha
    on Nov 16, 2026
    More actions

    @react Hi! I would like to work on this issue as part of my open-source contribution.

    I have reviewed the issue and would like to implement the proposed changes.

    Could you please assign this issue to me?

    Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bug reportneeds triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.