-
Notifications
You must be signed in to change notification settings - Fork 27.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VS Code auto-import of React Components broken in VS Code (Next.JS + React 17 JSX + TypeScript incompatibility) #27212
Comments
Does this also affect absolute imports and or aliases? // tsconfig.json
|
I think the correct approach here is to change to preserve only if you are using It's not optimal having to change your tsconfig.json everytime you restart the dev server. |
From what I can glean: This means that "preserve" should be fine, but TS/VSCode isn't handling it correctly. |
Looks like the underlying issue is in TypeScript: microsoft/TypeScript#41762 |
Typescript's design meeting over this: microsoft/TypeScript#46141 |
Looks like this has been fixed at TypeScript level microsoft/TypeScript#46368 |
Hopefully released in Typescript 4.5? |
Fixed in Typescript 4.5.2! After upgrading, make sure you're using the correct version in VSCode. View -> Command Palette -> type in "Typescript" and select "Typescript: Select Typescript version" and then select 4.5.2. Hope this helps! |
@mikelehen could you check the suggested changes? I am trying to reproduce, and it seems to work now, using TypeScript |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
What version of Next.js are you using?
10.2.3 (alse tested: 11.0.1)
What version of Node.js are you using?
12.22.1
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
n/a
Describe the Bug
When using Next.JS w/ TypeScript enabled, trying to auto-import react Components in VS Code incorrectly suggests adding
import React from 'react'
instead of the correct component import.The fix from a TypeScript / VS Code perspective seems to be setting
"jsx": "react-jsx"
in yourtsconfig.json
(see here). But if you do this in your next.js app, thenyarn dev
will "helpfully" undo it:Expected Behavior
Using VS Code's auto-import functionality should work out of the box in a Next.JS + TypeScript app.
To Reproduce
yarn create next-app --typescript
(accept defaultmy-app
name)code my-app
(to open VS Code).my-app/pages/index.tsx
file.<MyApp />
anywhere within theHome
component.MyApp
, hover over it and click "Quick Fix..." (or just press⌘.
shortcut on macOS)Result: It suggests: import default 'React' from module "react"
Expected: It should suggest: import default 'MyApp' from module "./_app"
Note: If you accept the first suggestion to add the
React
import, then triggering the quick fix a second time will suggest the correct import.The text was updated successfully, but these errors were encountered: