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.