VSCode does not auto-import from "react" in Next.js projects

Viewed 1093

* This is not a duplicate of this question; the accepted answer there is made for TypeScript and doesn't seem to work for JavaScript.

I am working on a Next.js project in Visual Studio Code, and when trying to auto-import anything from "react", the only auto-import suggestions come from "react.production.min" and "react.development".

I can manually import from "react", but even when I already have an import { ... } from "react" statement in the file, it still doesn't show up in the auto-import suggestions, and manually importing every hook I use can get quite tedious.

VSCode auto-import problem

Is there a way to fix this?

2 Answers

For me, installing @types/react fixes this problem.

If you are using typeScript then just need to add below single line code in next-env.d.ts

/// <reference types="@types/react" />
Related