{"id":26033,"library":"oc-template-handlebars-compiler","title":"OC Handlebars Template Compiler","description":"OC-Template-Handlebars-Compiler is the compiler module for OpenComponents (OC) that handles compilation of components using the Handlebars templating engine. This package supports both the `oc-template-handlebars` and legacy `handlebars` template types. As part of the OC ecosystem (version 6.7.0), it integrates with the OC registry to compile Handlebars templates into server-rendered components. It is actively maintained by the OpenComponents team and ships TypeScript types. Key differentiator: it is specifically built for OpenComponents' component architecture, unlike standalone Handlebars compilers, and provides seamless integration with OC's server-side rendering pipeline.","status":"active","version":"6.7.0","language":"javascript","source_language":"en","source_url":"https://github.com/opencomponents/base-templates","tags":["javascript","oc","opencomponents","typescript"],"install":[{"cmd":"npm install oc-template-handlebars-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add oc-template-handlebars-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add oc-template-handlebars-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"runtime dependency for Handlebars compilation","package":"handlebars","optional":false},{"reason":"extracts and precompiles the template","package":"oc-template-handlebars","optional":true}],"imports":[{"note":"Named export, not default. ESM and CJS both support named import.","wrong":"import compile from 'oc-template-handlebars-compiler'","symbol":"compile","correct":"import { compile } from 'oc-template-handlebars-compiler'"},{"note":"CommonJS require also works but ESM is preferred for tree-shaking. Named export as well.","wrong":"const getInfo = require('oc-template-handlebars-compiler').getInfo","symbol":"getInfo","correct":"import { getInfo } from 'oc-template-handlebars-compiler'"},{"note":"TypeScript type import should use `import type` to avoid runtime overhead. Types are bundled since v6.0.","wrong":"import { CompilerOptions } from 'oc-template-handlebars-compiler'","symbol":"oc-template-handlebars-compiler type","correct":"import type { CompilerOptions } from 'oc-template-handlebars-compiler'"}],"quickstart":{"code":"import { compile } from 'oc-template-handlebars-compiler';\nimport { getInfo } from 'oc-template-handlebars-compiler';\n\nconst template = '<div>{{message}}</div>';\nconst info = getInfo();\nconsole.log('Compiler info:', info);\n\nconst compiled = compile(template, { type: 'oc-template-handlebars' }, {\n  version: '6.0.0',\n  handlebars: require('handlebars')\n});\nconsole.log('Compiled component:', compiled);","lang":"typescript","description":"Demonstrates importing compile and getInfo, then compiling a simple Handlebars template with version and handlebars instance."},"warnings":[{"fix":"Update component type to 'oc-template-handlebars' or configure legacy support via options.","message":"v6.0.0 dropped support for legacy `handlebars` type without explicit configuration. Use `type: 'oc-template-handlebars'` instead.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Avoid using `getInfo`; rely on other OC APIs for version info.","message":"The `getInfo` export is deprecated as of v6.5.0. It may be removed in a future major version.","severity":"deprecated","affected_versions":">=6.5.0"},{"fix":"Always pass handlebars: require('handlebars') in the options object to compile().","message":"The `compile` function requires a Handlebars instance to be passed in options. Omitting it will throw a runtime error.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Ensure your bundler can resolve the main entry (CommonJS) or use a compatible module resolution strategy.","message":"ESM imports are supported but the package does not have a 'module' field in package.json; bundlers may need fallback to CommonJS.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Upgrade Node.js to >=12 and ensure handlebars >=4.0.0 is installed.","message":"Node.js <12 is no longer supported since v6.0.0. Handlebars 4.x is required.","severity":"breaking","affected_versions":">=6.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'npm install handlebars' in your project.","cause":"handlebars peer dependency not installed","error":"Error: Cannot find module 'handlebars'"},{"fix":"Change 'import compile from ...' to 'import { compile } from ...'.","cause":"Default import used instead of named import","error":"TypeError: compile is not a function"},{"fix":"Use type 'oc-template-handlebars' or enable legacy support by setting options.legacy = true.","cause":"Legacy type string used without proper configuration","error":"Error: No template found for type 'handlebars'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}