{"id":25285,"library":"esbuild-handlebars","title":"esbuild-handlebars","description":"An esbuild plugin for compiling Handlebars templates (.hbs, .handlebars) into JavaScript modules. Current stable version is 1.1.0. It resolves the 'Cannot read properties of undefined (reading call)' error common in other plugins, supports custom helpers/partials injection, and uses Handlebars precompilation for optimal performance. Key differentiators: fixes nested helper calls, integrates seamlessly with esbuild's build pipeline, and is lightweight with no extra runtime dependencies.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/PuAlbert/esbuild-plugin-handlebars","tags":["javascript"],"install":[{"cmd":"npm install esbuild-handlebars","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-handlebars","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-handlebars","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports a default function that takes an options object. ESM import is the recommended way, but CJS require works in Node.js.","wrong":"const hbsPlugin = require('esbuild-handlebars')","symbol":"default (plugin factory)","correct":"import hbsPlugin from 'esbuild-handlebars'"},{"note":"The package also exports 'handlebarsPlugin' as a named export. Use named import if you prefer explicit naming.","wrong":"import handlebarsPlugin from 'esbuild-handlebars'","symbol":"handlebarsPlugin (named export)","correct":"import { handlebarsPlugin } from 'esbuild-handlebars'"},{"note":"The package does not ship TypeScript types. You may need to declare a module or use @types/handlebars for type checking.","wrong":"import { hbsPlugin } from 'esbuild-handlebars'","symbol":"TypeScript usage","correct":"import hbsPlugin from 'esbuild-handlebars'"}],"quickstart":{"code":"const esbuild = require('esbuild');\nconst hbsPlugin = require('esbuild-handlebars');\n\nconst hbsOptions = {\n  filter: /\\.(hbs|handlebars)$/i,\n  additionalHelpers: {\n    equal: require('path').join(__dirname, 'helper', 'template', 'equal')\n  },\n  precompileOptions: {}\n};\n\nesbuild.build({\n  entryPoints: ['src/index.js'],\n  bundle: true,\n  outfile: 'dist/bundle.js',\n  plugins: [require('esbuild-handlebars')(hbsOptions)],\n}).catch(() => process.exit(1));","lang":"javascript","description":"Shows basic usage: require the plugin, create options with a filter and optional helpers, then add to esbuild plugins list."},"warnings":[{"fix":"Set the filter option to a RegExp that matches your Handlebars file extensions, e.g., /\\.(hbs|handlebars)$/i.","message":"The plugin only runs during esbuild's load phase; ensure your filter matches the file extensions you want to process.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use absolute or relative paths to .js files that export the helper/partial, not inline functions.","message":"additionalHelpers and additionalPartials expect file paths (strings) pointing to JavaScript modules that export the helper/partial function.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Add a declaration file (e.g., 'esbuild-handlebars.d.ts') with: declare module 'esbuild-handlebars' { export default function hbsPlugin(options?: any): any; export const handlebarsPlugin: typeof hbsPlugin; }","message":"The plugin does not provide TypeScript type definitions; using it in a TypeScript project may require custom type declarations.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Update to esbuild-handlebars v1.1.0, which resolves this issue. Install the latest version: npm install -D esbuild-handlebars@latest.","cause":"Using a version of the original plugin that doesn't handle nested helper calls correctly.","error":"Cannot read properties of undefined (reading 'call')"},{"fix":"Add the plugin to the 'plugins' array in your esbuild config: plugins: [require('esbuild-handlebars')(options)].","cause":"The plugin is not registered correctly, or esbuild doesn't have a loader for .hbs files.","error":"Error: No matching loader for \".hbs\" files"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}