VSCode not autosuggesting React imports and not underlining missing imports
Asked Answered
S

1

8

I'm struggling with Next.js project I'm working on using VSCode. It is based on simple npx create-next-app I'm writing a component (page) and of course need to use react hooks like useState

Before in my previous react projects (not nextjs), after hitting ctrl+space just after useState vscode was suggesting adding correct import from "react". Now it adds it like import { useRef, useState } from "react/cjs/react.production.min"; and it doesn't work...

I think it may be somehow related to .jsconfig file that I added to have absolute imports

  "compilerOptions": {
    "baseUrl": "."
  }
}

Before I added it, it was ok. But unfortunately even if I delete .jsconfig the problem is still there... How to fix it AND have absolute imports available?

The other issue is that in React projects VSCode was automatically underlining missing imports. In NextJS it does not. It's so annoying to look for all the imports that are missing, especially when copy-pasting a larger part of code.

I would highly appreciate any help with this! Thank you in advance!

Stereobate answered 24/5, 2022 at 13:12 Comment(3)
What about this answer? #35950885Testudo
So when I have .jsconfig file empty it indeed autosuggests correct imports. But I would like to have the absolute imports.Stereobate
https://mcmap.net/q/1472180/-vscode-does-not-auto-import-from-quot-react-quot-in-next-js-projectsBenefic
M
3

run npm i @types/react -D or yarn add @types/react -D

Medeah answered 17/12, 2022 at 4:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.