{"id":12798,"library":"angular-build-info","title":"Angular Build Information CLI","description":"angular-build-info is a Command Line Interface (CLI) tool designed to automate the collection of crucial build-related metadata for Angular applications. Upon execution, it generates a `build.ts` file, typically placed in the project's `src/` directory, containing details such as the application's version (from `package.json`), the current Git commit hash, the Git user, and a precise build timestamp. This generated file can then be directly imported and utilized within Angular components or services to display build information, useful for debugging, support, or informational purposes. The package is currently stable at version 2.0.1, having undergone a significant rewrite in version 2.0.0. Releases appear to follow an as-needed cadence, focusing on bug fixes and enhancements. Its primary differentiator is its simplicity and direct integration into existing Angular CLI build workflows via `package.json` scripts, providing an easily consumable TypeScript module.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/inexio/angular-build-info","tags":["javascript","angular","angular2","build-info","build","cli","information"],"install":[{"cmd":"npm install angular-build-info","lang":"bash","label":"npm"},{"cmd":"yarn add angular-build-info","lang":"bash","label":"yarn"},{"cmd":"pnpm add angular-build-info","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The `buildInfo` object is a named export from the generated `build.ts` file. The path is relative to the consuming file, assuming `build.ts` is in `src/`.","wrong":"const buildInfo = require('../build');","symbol":"buildInfo","correct":"import { buildInfo } from '../build';"}],"quickstart":{"code":"npm i -g angular-build-info\n\n# Initialize the build.ts file in your src/ folder\nangular-build-info --init\n\n# Add to package.json scripts\n// package.json\n{\n  \"scripts\": {\n    \"build\": \"angular-build-info && ng build\",\n    \"deploy\": \"angular-build-info && ng build --prod && ./deploy\"\n  }\n}\n\n// app.component.ts (example usage)\nimport { Component } from \"@angular/core\";\nimport { buildInfo } from \"../build\";\nimport { environment } from \"../environments/environment\";\n\n@Component({\n    selector: \"app-root\",\n    templateUrl: \"./app.component.html\",\n    styleUrls: [\"./app.component.css\"]\n})\nexport class AppComponent {\n    constructor() {\n        console.log(\n            `\\n%cBuild Info:\\n\\n` +\n                `%c ❯ Environment: %c${environment.production ? \"production 🏭\" : \"development 🚧\"}\\n` +\n                `%c ❯ Build Version: ${buildInfo.version}\\n` +\n                ` ❯ Build Timestamp: ${buildInfo.timestamp}\\n` +\n                ` ❯ Build Message: %c${buildInfo.message || \"<no message>\"}\\n`,\n            \"font-size: 14px; color: #7c7c7b;\",\n            \"font-size: 12px; color: #7c7c7b\",\n            environment.production ? \"font-size: 12px; color: #95c230;\" : \"font-size: 12px; color: #e26565;\",\n            \"font-size: 12px; color: #7c7c7b\",\n            \"font-size: 12px; color: #bdc6cf\"\n        );\n    }\n}","lang":"typescript","description":"This quickstart demonstrates how to install `angular-build-info`, initialize the `build.ts` file, configure your Angular project's `package.json` to automatically update build information, and then import and display this data within an Angular component's browser console."},"warnings":[{"fix":"Review the official `angular-build-info` GitHub repository for detailed migration guides and updated usage instructions when upgrading to v2.x.","message":"Version 2.0.0 introduced a \"Massive v2-Rewrite\" which likely includes breaking changes in CLI arguments, configuration, or the structure/content of the generated `build.ts` file. Users upgrading from v1.x should consult the project's GitHub repository for specific migration instructions.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure Git is installed and accessible in your system's PATH, and that your Angular project is initialized as a Git repository (`git init`).","message":"`angular-build-info` relies on Git to fetch commit hash and user information. If Git is not installed on the build environment or the project directory is not a Git repository, the CLI may fail or produce incomplete build information (e.g., missing hash/user).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always prepend `angular-build-info &&` to your `ng build` command in `package.json` scripts. Example: `\"build\": \"angular-build-info && ng build --prod\"`.","message":"For the `build.ts` file to contain the latest information, the `angular-build-info` command must be executed *before* `ng build` (or similar build commands) in your `package.json` scripts. Failure to do so will result in outdated or incorrect build metadata.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Initialize your project as a Git repository using `git init` in your project's root directory.","cause":"`angular-build-info` was executed in a directory that is not a Git repository.","error":"Error: Failed to run git command: fatal: not a git repository (or any of the parent directories): .git"},{"fix":"Ensure `angular-build-info --init` has been run at least once to create the file, and that `angular-build-info` is executed before `ng build` in your `package.json` scripts (e.g., `\"build\": \"angular-build-info && ng build\"`). Verify `src/build.ts` exists.","cause":"The `build.ts` file was not generated or is not located at the expected path (`src/build.ts` by default) when Angular tries to compile.","error":"Module not found: Error: Can't resolve '../build' in '.../app.component.ts'"},{"fix":"Double-check your `package.json` build scripts to ensure `angular-build-info` runs correctly before `ng build`. You might also need to clear build caches or force a clean build, e.g., by deleting `dist/` and `node_modules/.angular/cache/`.","cause":"The `angular-build-info` command was not executed or failed to update the `build.ts` file prior to the last `ng build`, or aggressive caching is preventing a fresh build.","error":"Console logs show outdated build version or timestamp after a new deployment."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null}