Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-import Javascript module in Vscode using Shortcut (Ctrl + .)

If my JS code uses a module/varaible that is not yet imported, VSCode will underline it in red

Image showing underline in VSCode

How can VSCode be configured such that we can select the unimported variable, either press a shortcut or select something from the right-click menu, and select the appropriate module to be imported.

Similar to the Ctrl + . auto-import shortcut when dealing with Rust files

like image 226
gameveloster Avatar asked May 20 '26 22:05

gameveloster


1 Answers

Normally, in Visual Studio Code, if you type in a variable or function that isn't imported, then Visual Studio Code will auto-correct it, if you select it.

For example, if I am typing half the name of a function, it will infer that I want a function, and when I hit Tab/Enter, it will autocomplete it, and import it.

See the GIF below for a visual example.

Example GIF

like image 152
Viradex Avatar answered May 22 '26 12:05

Viradex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!