How to force tsc to ignore node_modules folder?

Cover Image for How to force tsc to ignore node_modules folder?
Matheus Mello
Matheus Mello
published a few days ago. updated a few hours ago

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! ✨🚀


More Stories

Cover Image for How can I echo a newline in a batch file?

How can I echo a newline in a batch file?

updated a few hours ago
batch-filenewlinewindows

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Matheus Mello
Matheus Mello
Cover Image for How do I run Redis on Windows?

How do I run Redis on Windows?

updated a few hours ago
rediswindows

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Matheus Mello
Matheus Mello
Cover Image for Best way to strip punctuation from a string

Best way to strip punctuation from a string

updated a few hours ago
punctuationpythonstring

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Matheus Mello
Matheus Mello
Cover Image for Purge or recreate a Ruby on Rails database

Purge or recreate a Ruby on Rails database

updated a few hours ago
rakeruby-on-railsruby-on-rails-3

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my

Matheus Mello
Matheus Mello