{"library":"next-build-id","title":"Consistent Git-based Build ID for Next.js","description":"next-build-id is a utility package for Next.js applications, currently at version 3.0.0. It addresses a common issue in multi-server deployments where different instances of a Next.js app might have varying build IDs, leading to \"invalid build file hash\" errors for clients. This package provides a mechanism to generate a consistent build ID, derived from the local Git repository's state, specifically the latest commit hash (`git rev-parse HEAD`) or a description based on the most recent Git tag (`git describe --tags`). It exports an asynchronous function (the primary export) and a synchronous variant, both intended to be used with Next.js's `generateBuildId` configuration option in `next.config.js`. The package helps ensure that all deployed instances of a Next.js application serve assets built with the same identifier, crucial for load-balanced environments without sticky sessions where apps are built directly on each server.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install next-build-id"],"cli":null},"imports":["import nextBuildId from 'next-build-id';","import nextBuildId from 'next-build-id'; const buildIdSync = nextBuildId.sync({ dir: __dirname });"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"// next.config.js\nconst nextBuildId = require('next-build-id');\n\n/** @type {import('next').NextConfig} */\nconst nextConfig = {\n  // Required to ensure consistent build IDs across multiple servers\n  // and prevent 'invalid build file hash' errors.\n  generateBuildId: async () => {\n    // Use the latest git commit hash as the build ID by default.\n    // Pass { describe: true } to use git tags instead (e.g., 'v1.0.0-19-ga8f7eee').\n    // The `dir` option should point to your project's root containing the .git folder.\n    return nextBuildId({ dir: __dirname });\n  },\n  // Other Next.js configurations here...\n};\n\nmodule.exports = nextConfig;","lang":"javascript","description":"Demonstrates how to integrate next-build-id into your Next.js configuration to generate a consistent, git-based build ID, preventing deployment issues.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}