S sabeer
S sabeer

Reputation: 39

Cannot find module '../assets/json/example.json'

enter image description herestrong text

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

Upvotes: 1

Views: 4686

Answers (4)

Sorin Veștemean
Sorin Veștemean

Reputation: 1920

Copy this in your tsconfig.json file , inside compilerOptions:

"resolveJsonModule": true,
"esModuleInterop": true

Upvotes: 0

Aairi Rajapaksha
Aairi Rajapaksha

Reputation: 56

Try to solve it this way. Its work for me.
Create file called json-typings.d.ts in src/app folder. and typing file as follows:

declare module "*.json" {
  const value: any;
  export default value;
}

Then you can import Json files just like TypeScript 2.9+.

import * as info from "info.json";

Upvotes: 3

Serkan
Serkan

Reputation: 150

open File tsconfig.json and change resolveJsonModule : to true.

{
    resolveJsonModule:true,
}

Upvotes: 5

Siddharth Pal
Siddharth Pal

Reputation: 1458

Please add in your tslint.json file

{
   "linterOptions": {
       "exclude": [
          "*.json",
          "**/*.json"
       ]  
   }
}

**/*.json to be recursive

Upvotes: 1

Related Questions