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 showFix it fast
Most common cause, 1 of 4JavaScript 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.
// jsconfig.json
{
"compilerOptions": {
"checkJs": true
// keep existing options such as paths here
}
}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.
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.
ls jsconfig.json tsconfig.json 2>/dev/null
grep -n "checkJs\|\"include\"" jsconfig.json tsconfig.json 2>/dev/null
npm ls @types/reactThen find the line you see in this list and open its fix:
- 1JavaScript files are not type-checked
The files end in .js or .jsx, jsconfig.json has no checkJs, and the files do not start with // @ts-check - 2Auto import suggestions are switched off in settings
User or workspace settings contain "js/ts.suggest.autoImports": false - 3React's type declarations are not available
npm ls @types/react prints an empty tree, or a .tsx file reports Could not find a declaration file for module 'react' - 4The file is outside the jsconfig or tsconfig project
JavaScript: 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 underlineCould 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.
grep -n "checkJs" jsconfig.jsonFix
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.
// 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'.
# close and reopen the file in VS CodeConfirmed by code.visualstudio.com
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.
grep -n "autoImports" .vscode/settings.json 2>/dev/nullFix
Delete the entry or set it to true, both in .vscode/settings.json and in your user settings.json.
// .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.
# VS Code: type useSt in a component file and look at the suggestion detailsConfirmed by code.visualstudio.com
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.
npm ls @types/react @types/react-dom
which npmFix
Install the type packages that the React docs list, then close and reopen VS Code so the language service reads them.
npm install --save-dev @types/react @types/react-domVerify
Hovering useState shows its typed signature, and typing it offers an import from react.
npm ls @types/reactConfirmed by react.dev
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.
grep -n -A3 "\"include\"" jsconfig.json tsconfig.json 2>/dev/nullFix
Add the folders that hold your code to include, and keep node_modules in exclude.
// 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.
# VS Code: Command Palette > JavaScript: Go to Project ConfigurationConfirmed by code.visualstudio.com
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.