Fix Node.js imports types errors in VS Code
Had this error (more a warning) in a project:
VS Code complained Node.js types could not be found.
So I installed them:
npm install -D @types/node
Then added them to the compilerOptions in tsconfig.json
{
//...
"compilerOptions": {
"types": [
"node"
]
},
}
That still didn’t solve so I dropped node_modules:
rm -rf node_modules
rm -f package-lock.json
npm cache clean --force
npm install
Finally, restarting VS Code made them disappear (not sure if reinstalling modules had any effect, first try restarting VS Code after adding the types).
→ Get my Node.js Handbook
→ I wrote 17 books to help you become a better developer:
- C Handbook
- Command Line Handbook
- CSS Handbook
- Express Handbook
- Git Cheat Sheet
- Go Handbook
- HTML Handbook
- JS Handbook
- Laravel Handbook
- Next.js Handbook
- Node.js Handbook
- PHP Handbook
- Python Handbook
- React Handbook
- SQL Handbook
- Svelte Handbook
- Swift Handbook
Also, JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025