How to pull application version (or import package.json file)? Google does not help :(

Discussão em 'Angular' iniciado por Budda, Fevereiro 13, 2025.

  1. Budda

    Budda Guest

    In my Angular application, I'd like to display the version from the package.json file.

    I know that to import it I need to allow importing json and for this tsconfig.json file needs to get a few extra lines:

    {
    "compilerOptions": {
    "module": "commonjs",
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "moduleResolution": "node"
    }
    }


    I did this, but after that when I import json file in my component class:

    import { myPackage } from '../../../package.json';


    I still get an error:


    Cannot find module '../../../package.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.ts(2732)
    ​

    And problem is not with path as I put another simple json file to the same folder but getting the same error.

    I've googled and seen many examples that speak about '--resolveJsonModule', but it seems like I do all what's needed... but it still does not work.

    I also restarted VScode and angular service - it did not help.

    I use Angular 10.0.11 and TS 3.9.7

    Please advise! Thanks!

    Continue reading...

Compartilhe esta Página