Can't import a json file in TypeScript

I have the following code:

import data from "./data.json" with { type: "json" };

Running tsc leads to the following error:

index.ts:20:18 - error TS2732: Cannot find module './data.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.

How can I fix it?

Make sure you have set resolveJsonModule to true in your tsconfig.json file:

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