You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSX import fixes do not support new React JSX Transform (without react import) #41762
React 17 introduced a new JSX transform which does not require react to be imported in every file. Support for this was added in TypeScript 4.1. However vscode is still suggesting/requiring the react import before other JSX import fixes are suggested.
Add a src/Test.tsx file with content export default function Test() { return <App />; }. It should show a problem Cannot find name 'App'..
Click to show fixes. It unnecessarily suggests/requires import default 'React' from module "react" before it will suggest the desired import default 'App' from module "./App".
In short, you can't get help with JSX imports without littering your files with unnecessary react imports.
Does this issue occur when all extensions are disabled?: Yes
changed the title [-]JSX import refactoring does not support new React JSX Transform (without react import)[/-][+]JSX import fixes do not support new React JSX Transform (without react import)[/+]on Dec 1, 2020
One workaround I found is: Instead of pressing cmd+. to open the auto suggest panel, remove the last letter of the component and type it back. You should see the suggest panel come up with the component name instead of the import React from 'react' suggestion.
Reacted by Chris Duff, Mikis Woodwinter, Paden Portillo, Felipe Munhoz, Laurence Ede, Matthew Jeorrett, Jonathan Madelaine, Ben Coullie, Markus Ånöstam, Frank Sandqvist and 2 more
Reacted by Fernando Montoya, zen-ventzi-marinov, Shahaed Hasan, Bartosz Brzeziński and Case Walker
I tried this workaround too, but when I am trying to fix all missing imports, this is a very annoying task. Instead, I import React from 'react'; and then fix all missing imports, and then it is as simple as removing the react import.
I tried this workaround too, but when I am trying to fix all missing imports, this is a very annoying task. Instead, I import React from 'react'; and then fix all missing imports, and then it is as simple as removing the react import.
I have a precommit hook that runs some modified version of that react-jsx codemod as part of lint staged. VERY UGLY solution but that's the best I could do atm. :/
Christopher Lenz (@cmlenz) If it is the same then I might have bad news because I pulled in the nightly with #41950 (the fix for #41920) and this issue is still present :-\
Any ideas why the TS engine doesn't pick up react if you set jsx to "preserve" or the reasoning behind the decision?
The handbook on it says it only affects the emit stage and does not affect type-checking.
If I'm working in other configurations and React is at v17, then I shouldn't have to have React imported in each file. If I have my own transpilation system, such as Next, Babel, etc. I'd still like to not have VSCode complaining that React isn't imported into the file.
Activity
[-]JSX import refactoring does not support new React JSX Transform (without react import)[/-][+]JSX import fixes do not support new React JSX Transform (without react import)[/+]RyanCavanaugh commentedon Dec 3, 2020
We're still working on exactly figuring out how the new helpful automatic import behavior should interact with TS's framework-agnostic view of JSX
kuasha420 commentedon Dec 31, 2020
Any progress made on this yet?
nahtnam commentedon Jan 12, 2021
One workaround I found is: Instead of pressing
cmd+.to open the auto suggest panel, remove the last letter of the component and type it back. You should see the suggest panel come up with the component name instead of theimport React from 'react'suggestion.advaiyalad commentedon Jan 13, 2021
I tried this workaround too, but when I am trying to fix all missing imports, this is a very annoying task. Instead, I
import React from 'react';and then fix all missing imports, and then it is as simple as removing the react import.kuasha420 commentedon Jan 13, 2021
I have a precommit hook that runs some modified version of that react-jsx codemod as part of lint staged. VERY UGLY solution but that's the best I could do atm. :/
Paden commentedon Jan 28, 2021
Since JSX is no longer apart of a single framework, does this still apply?
cmlenz commentedon Feb 1, 2021
I think this is the same as #41920
jmadelaine commentedon Mar 17, 2021
Any updates on this?
zackdotcomputer commentedon Mar 22, 2021
Christopher Lenz (@cmlenz) If it is the same then I might have bad news because I pulled in the nightly with #41950 (the fix for #41920) and this issue is still present :-\
10 remaining items
advaiyalad commentedon Jul 20, 2021
@nghiepit Are you using next.js?
nghiepdev commentedon Jul 20, 2021
PythonCreator27 Yes. I'm using Next.js
This is my
tsconfig.jsonandVSCode 1.58.2{ "compilerOptions": { "target": "es5", "lib": ["dom", "dom.iterable", "esnext"], "module": "esnext", "jsx": "preserve", "baseUrl": ".", "strict": true, "noEmit": true, "allowJs": true, "skipLibCheck": true, "moduleResolution": "node", "esModuleInterop": true, "isolatedModules": true, "resolveJsonModule": true, "forceConsistentCasingInFileNames": true }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], "exclude": ["node_modules", ".next"] }kuasha420 commentedon Jul 20, 2021
"jsx": "preserve",will not work here. But nextjs won't work without preserve. I think Nextjs needs to fix this on their side.Admiralfeb commentedon Sep 19, 2021
Any ideas why the TS engine doesn't pick up react if you set jsx to "preserve" or the reasoning behind the decision?
The handbook on it says it only affects the emit stage and does not affect type-checking.
If I'm working in other configurations and React is at v17, then I shouldn't have to have React imported in each file. If I have my own transpilation system, such as Next, Babel, etc. I'd still like to not have VSCode complaining that React isn't imported into the file.
Shahaed commentedon Sep 23, 2021
Would love a response from the Typescript team on this
andrewbranch commentedon Sep 27, 2021
Looking into it 👍
pvinis commentedon Mar 23, 2022
what about
"jsx":"react-native"? should there be a"jsx":"react-native-jsx"too?