[Solved] "Cannot find module *.json" TypeScript Error

May 28, 2023

[Solved] "Cannot find module *.json" TypeScript Error

Because TypeScript does not support resolving JSON files by default. When trying to import a JSON file in the TypeScript project, may see the following error.

Cannot find module '*.json'. Consider using '--resolveJsonModule' to import module with '.json' extension

How to solve this error.

Add the resolveJsonModule directive under compilerOptions in tsconfig.json file.

Example:

{
  "compilerOptions": {
    "resolveJsonModule": true,
  }
}