0

i try to display the build version on my application, but when i run the app i have the error : process is not define.

How can i display the version ?

 constructor( protected commonService: CommonService, protected hideShowDeleteWidgetsService: HideShowDeleteWidgetsService, protected fccGlobalConstantService: FccGlobalConstantService , protected videoChatService: VideoChatService) {
 super(commonService, hideShowDeleteWidgetsService, fccGlobalConstantService, videoChatService);
console.log(process.env.npm_package_version);
console.log(process.env.VERSION);
console.log(process.version);
console.log(process);
}
ElieA
  • 1
  • 2
  • Unless you use SSR, you do not have access to process. That is a node thing so not available in the browser (neither is package.json btw) – MikeOne Apr 04 '22 at 15:29
  • 1
    Possible duplicate: https://stackoverflow.com/questions/34907682/how-to-display-the-app-version-in-angular – Bruno Miguel Apr 04 '22 at 15:44

1 Answers1

0

From nodejs.org

The process object provides information about, and control over, the current Node.js process

After the application is built, it becomes a static application so, you don't have access to this as there is no Node process anymore.

Instead, you can generate a file during the build process in order to put aside every useful info.

package.json

  {
  [...]
  "scripts": {
    "prebuild": "whatever.sh >> src/info.js|json|txt",

Then you can access this file at runtime to get the needed information

Arnaud Denoyelle
  • 29,980
  • 16
  • 92
  • 148