Error: “Cannot find module ‘./path/to/data.json’. Consider using ‘–resolveJsonModule’ to import module with ‘.json’ extension”
1. Allow JSON data
Loading large JSON files may consume a lot of memory, which is why TypeScript requires conscious enablement for importing JSON files. To do so, edit the TypeScript config file, found in the app root folder:
// FILE: tsconfig.json
"angularCompilerOptions": {
...
"resolveJsonModule": true
...
}
Code language: JavaScript (javascript)
Error: “Cannot find module ‘./path/to/data.json’. Consider using ‘–resolveJsonModule’ to import module with ‘.json’ extension”
2. Import JSON data
Now you can import the JSON data without an error.
import * as data from './path/to/data.json';
console.log(data);
Code language: JavaScript (javascript)