I need to display the version from the package.json file in my Angular application.
To import it, I allowed importing json by adding a few extra lines in tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
"moduleResolution": "node"
}
}
Even after making these changes, when I try to import the json file in my component class:
import { myPackage } from '../../../package.json';
I still encounter this error:
Cannot find module '../../../package.json'. Consider using '--resolveJsonModule' to import modules with '.json' extension.ts(2732)
The issue is not with the path as I have tried putting another simple json file in the same folder and encountered the same error.
Despite researching and following examples related to '--resolveJsonModule', it seems like I have done everything correctly... but it just doesn't work.
I have also restarted VScode and the angular service, but it hasn't resolved the problem.
I am currently using Angular 10.0.11 and TS 3.9.7
Please provide guidance! Thank you!