Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

VS Code offers no auto imports and does not underline a missing import

Your error

Typing useState or a component name shows no Auto import suggestion2 more lines it can show

Fix it fast

Most common cause, 1 of 4

JavaScript files are not type-checked

Turn on checkJs in the compilerOptions of jsconfig.json, keeping the options already there, or add // @ts-check as the first line of single files.

Fix
// jsconfig.json
{
  "compilerOptions": {
    "checkJs": true
    // keep existing options such as paths here
  }
}
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

In a Next.js JavaScript project, VS Code does not type-check .js and .jsx files until checkJs or // @ts-check turns it on, so a component used without its import is not underlined. Auto import suggestions also disappear when js/ts.suggest.autoImports is false, when React's types are missing, or when the file sits outside the jsconfig project. Applies to VS Code 1.147.

  • Applies to VS Code 1.147, Next.js 16.4, React 19.3, @types/react 19.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

From the project root, see which project file owns the code, whether JavaScript checking is switched on in it, and whether React's types are installed. Then open the failing file and run JavaScript: Go to Project Configuration from the Command Palette; a notification instead of a config file means the file belongs to no project.

Run this first
ls jsconfig.json tsconfig.json 2>/dev/null
grep -n "checkJs\|\"include\"" jsconfig.json tsconfig.json 2>/dev/null
npm ls @types/react

Then find the line you see in this list and open its fix:

  1. 1JavaScript files are not type-checkedThe files end in .js or .jsx, jsconfig.json has no checkJs, and the files do not start with // @ts-check
  2. 2Auto import suggestions are switched off in settingsUser or workspace settings contain "js/ts.suggest.autoImports": false
  3. 3React's type declarations are not availablenpm ls @types/react prints an empty tree, or a .tsx file reports Could not find a declaration file for module 'react'
  4. 4The file is outside the jsconfig or tsconfig projectJavaScript: Go to Project Configuration shows a notification that the file is not part of a project, or include lists only src while the code lives in app

What does the error look like?

  • Typing useState or a component name shows no Auto import suggestion
  • <Button /> is used without an import and the editor shows no red underline
  • Could not find a declaration file for module 'react'.

Cause 1 of 4

JavaScript files are not type-checked

You seeThe files end in .js or .jsx, jsconfig.json has no checkJs, and the files do not start with // @ts-check

Check

VS Code leaves a missing import unflagged in a .js or .jsx file because type checking of JavaScript is opt-in. A project created as JavaScript gets IntelliSense from inferred types, but an unknown name such as a component you forgot to import is only reported once checking is enabled for that file or project.

Check
grep -n "checkJs" jsconfig.json

Fix

Turn on checkJs in the compilerOptions of jsconfig.json, keeping the options already there, or add // @ts-check as the first line of single files. Files outside any jsconfig or tsconfig project follow the js/ts.implicitProjectConfig.checkJs setting instead.

Fix
// jsconfig.json
{
  "compilerOptions": {
    "checkJs": true
    // keep existing options such as paths here
  }
}

Verify

Reopen the file; the component without an import is underlined with Cannot find name 'Button'.

Verify
# close and reopen the file in VS Code

Confirmed by code.visualstudio.com

Did this fix it?

Cause 2 of 4

Auto import suggestions are switched off in settings

You seeUser or workspace settings contain "js/ts.suggest.autoImports": false

Check

No Auto import entry appears in the suggestion list when js/ts.suggest.autoImports is false. VS Code's JavaScript docs name that setting as the switch that disables auto imports, and it can sit in the workspace's .vscode/settings.json as well as in your user settings.

Check
grep -n "autoImports" .vscode/settings.json 2>/dev/null

Fix

Delete the entry or set it to true, both in .vscode/settings.json and in your user settings.json.

Fix
// .vscode/settings.json
{
  "js/ts.suggest.autoImports": true
}

Verify

Type the first letters of a hook such as useSt; the list shows useState together with the module it will be imported from.

Verify
# VS Code: type useSt in a component file and look at the suggestion details

Confirmed by code.visualstudio.com

Did this fix it?

Cause 3 of 4

React's type declarations are not available

You seenpm ls @types/react prints an empty tree, or a .tsx file reports Could not find a declaration file for module 'react'

Check

VS Code cannot suggest imports from react when it has no declarations for the package: react itself ships JavaScript only, and its types come from @types/react. A TypeScript project needs that package installed. A JavaScript project gets typings through automatic type acquisition, which in turn needs npm; when VS Code warns that npm is not installed although it is, the docs point to the js/ts.tsserver.npm.path setting.

Check
npm ls @types/react @types/react-dom
which npm

Fix

Install the type packages that the React docs list, then close and reopen VS Code so the language service reads them.

Fix
npm install --save-dev @types/react @types/react-dom

Verify

Hovering useState shows its typed signature, and typing it offers an import from react.

Verify
npm ls @types/react

Confirmed by react.dev

Did this fix it?

Cause 4 of 4

The file is outside the jsconfig or tsconfig project

You seeJavaScript: Go to Project Configuration shows a notification that the file is not part of a project, or include lists only src while the code lives in app

Check

Auto imports draw on the symbols of the current project, so a component file left out by include is not offered as an import, and the project's checkJs does not apply to it either. Once include is present, only the files it names belong to the project, and its paths are resolved from the folder that holds jsconfig.json.

Check
grep -n -A3 "\"include\"" jsconfig.json tsconfig.json 2>/dev/null

Fix

Add the folders that hold your code to include, and keep node_modules in exclude.

Fix
// jsconfig.json
{
  "compilerOptions": { "checkJs": true },
  "include": ["app", "components", "lib", "src"],
  "exclude": ["node_modules"]
}

Verify

Go to Project Configuration now opens jsconfig.json for the file, and its exports appear as auto import suggestions in other files.

Verify
# VS Code: Command Palette > JavaScript: Go to Project Configuration

Confirmed by code.visualstudio.com

Did this fix it?

How do I stop it coming back?

  • Commit a .vscode/settings.json only with settings the team agrees on, and review it when suggestions change for everyone at once.
  • Keep @types/react and @types/react-dom in devDependencies next to react, at the same major version.
  • Enable checkJs in jsconfig.json when the project starts, so missing imports show up while the file count is still small.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, QistLock, Taskvare.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.