How to force tsc to ignore node_modules folder?



How to 🤔 force tsc to ignore node_modules folder? 📦
Are you tired of seeing those annoying errors from the node_modules
folder when running your tsc
build tasks? 😩 Don't worry, we've got you covered! In this blog post, we'll address this common issue and provide you with easy solutions to force tsc
to ignore the node_modules
folder. Let's dive right in! 💪
The Problem 😫
So, you're using tsc
build tasks in your project and every time you run it, you encounter the same errors from the node_modules
folder. It's quite frustrating, right? Here's a sneak peek of the errors you might be seeing:
node_modules/@types/node/index.d.ts(6208,55): error TS2304: Cannot find name 'Map'.
node_modules/@types/node/index.d.ts(6215,55): error TS2304: Cannot find name 'Set'.
node_modules/@types/node/index.d.ts(6219,64): error TS2304: Cannot find name 'Symbol'.
node_modules/@types/node/index.d.ts(6225,59): error TS2304: Cannot find name 'WeakMap'.
node_modules/@types/node/index.d.ts(6226,59): error TS2304: Cannot find name 'WeakSet'.
The Solution 🎉
To overcome this issue and force tsc
to ignore the node_modules
folder, you need to make some adjustments to your tsconfig.json
file.
Open your tsconfig.json
file and look for the exclude
property. If you don't have one, go ahead and add it to the root level of your tsconfig.json
file. Your tsconfig.json
should now look something like this:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"strict": false,
"noImplicitAny": false,
"strictPropertyInitialization": false,
"esModuleInterop": true
},
"include": [
"src/*"
],
"exclude": [
"node_modules",
"./node_modules",
"./node_modules/*",
"./node_modules/@types/node/index.d.ts"
]
}
Notice the exclude
property? It's where the magic happens! By adding the node_modules
folder to the exclude
array, you're telling tsc
to ignore this folder during compilation. 🙅♂️
What's Next? 🚀
Once you've made the necessary changes to your tsconfig.json
file, save it and rerun your tsc
build tasks. You'll notice that the errors from the node_modules
folder magically disappear! 🎩💫
Your Turn! 📣
Give these solutions a try and see how they work for you. If you have any questions or run into any issues, feel free to leave a comment below. We'd love to hear your experiences and help you out! 😊
Remember, sharing is caring! If you found this blog post helpful, hit that share button and spread the knowledge with your fellow developers. Let's make everyone's development experience smoother with tsc
! 🤗💻
Happy coding! ✨🚀