Categories
TypeScript Answers

How to fix the ‘Cannot find module’ error for paths that are in TypeScript tsconfig.json?

Spread the love

Sometimes, we want to fix the ‘Cannot find module’ error for paths that are in TypeScript tsconfig.json.

In this article, we’ll look at how to fix the ‘Cannot find module’ error for paths that are in TypeScript tsconfig.json.

How to fix the ‘Cannot find module’ error for paths that are in TypeScript tsconfig.json?

To fix the ‘Cannot find module’ error for paths that are in TypeScript tsconfig.json, we need to add all the paths that we want the TypeScript compiler to pick up.

For instance, we write

{
  "compilerOptions": {
    "baseUrl": ".",
    //...
    "paths": {
      "@project/app/modules/*": ["src/modules/*"],
      "@project/server/data/*": ["server/src/json/*"]
    }
  },

  "include": ["./src", "./server"]
}

in tsconfig.json so that the src/modules/* and server/src/json/* directories and their children are all picked up by TypeScript compiler.

Conclusion

To fix the ‘Cannot find module’ error for paths that are in TypeScript tsconfig.json, we need to add all the paths that we want the TypeScript compiler to pick up.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *