{"id":22039,"library":"rollup-plugin-git-info","title":"rollup-plugin-git-info","description":"A Rollup plugin that injects git build metadata (branch, commit hash, abbreviated hash, version, dates) into imported package.json files. Version 1.0.0 requires Node.js 12+ and Rollup 2+. This plugin is minimal and focused: it relies on @rollup/plugin-json for JSON handling and git CLI commands for data collection. Unlike alternatives that use environment variables or require manual configuration, it automatically populates standard fields like gitVersion and buildDate with no setup beyond adding the plugin.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/vapier/rollup-plugin-git-info","tags":["javascript","git","rollup","rollup-plugin"],"install":[{"cmd":"npm install rollup-plugin-git-info","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-git-info","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-git-info","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for JSON file transformation; all options from that plugin are inherited.","package":"@rollup/plugin-json","optional":false}],"imports":[{"note":"ESM-only export; CommonJS require() will fail.","wrong":"const gitInfo = require('rollup-plugin-git-info');","symbol":"gitInfo","correct":"import gitInfo from 'rollup-plugin-git-info';"},{"note":"If using CommonJS, must access .default property.","wrong":"const gitInfo = require('rollup-plugin-git-info');","symbol":"gitInfo","correct":"const gitInfo = require('rollup-plugin-git-info').default;"},{"note":"Default export only; named import will be undefined.","wrong":"import { gitInfo } from 'rollup-plugin-git-info';","symbol":"gitInfo","correct":"import gitInfo from 'rollup-plugin-git-info';"}],"quickstart":{"code":"import gitInfo from 'rollup-plugin-git-info';\nimport json from '@rollup/plugin-json';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    dir: 'dist',\n    format: 'es',\n  },\n  plugins: [\n    json(),\n    gitInfo(),\n  ],\n};","lang":"javascript","description":"Basic Rollup configuration using gitInfo plugin with @rollup/plugin-json to expose git metadata in package.json imports."},"warnings":[{"fix":"npm install @rollup/plugin-json --save-dev and add json() before gitInfo().","message":"@rollup/plugin-json must be installed separately and declared before gitInfo in plugins array.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure imports reference the correct package.json relative to the module.","message":"The plugin only works if you import './package.json' in your source; importing from a different path will not include metadata.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set cwd option to the correct directory for each package.","message":"git version is computed from the repository where package.json resides; using a monorepo with multiple package.json files may produce unexpected results.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Handle 'HEAD' in application logic or use a fallback branch name.","message":"The gitBranch field will be 'HEAD' in detached head state, which may break tools expecting a proper branch name.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Test date output across target git versions; consider using dateCommand for full control.","message":"The dateFormat option uses git log --date format; custom date formats may break with git version mismatches.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run: npm install @rollup/plugin-json --save-dev","cause":"@rollup/plugin-json is a required peer dependency but not installed.","error":"Error: Cannot find module '@rollup/plugin-json'"},{"fix":"Use: import gitInfo from 'rollup-plugin-git-info';","cause":"Incorrect import syntax, likely named import instead of default.","error":"TypeError: gitInfo is not a function"},{"fix":"Initialize a git repository: git init","cause":"The plugin requires a .git directory in the project root.","error":"Error: No git repository found in /path/to/project"},{"fix":"Switch to import syntax or use .default property: const gitInfo = require('rollup-plugin-git-info').default;","cause":"The plugin is ESM-only and cannot be used with CommonJS require directly.","error":"SyntaxError: Unexpected token 'export'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}