1

When I tried to display the version from package.json in local(dev mode) in angular, I was able to do it. for eg

import {version} from '../../package.json';
const VERSION = `${version}-a.a.a-b.b.b`;
But, in prod mode, when I tried to do the same, the VERSION value is getting displayed as '[Object object]-a.a.a-b.b.b'. Instead if

const VERSION = ${version};

The VERSION value is getting displayed properly as '1.0.0'. The issue occurs when I tried to append the version value from package.json to a string in app.module.ts when the app is built in prod mode.

I tried to check the typeof version from package.json, it returned string.

I need to display the version from package.json appended to a string value in app.module.ts in prod mode in angular. kindly help. thanks

adhs91
  • 152
  • 1
  • 6

1 Answers1

0

you can use environment.ts file for that. try this

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

export const environment = {
    VERSION: version,
};

You can now use environment. VERSION constant use in your application.

Shailesh Ladumor
  • 7,052
  • 5
  • 42
  • 55