OC Handlebars Template Compiler
raw JSON → 6.7.0 verified Fri May 01 auth: no javascript
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.
Common errors
error Error: Cannot find module 'handlebars' ↓
cause handlebars peer dependency not installed
fix
Run 'npm install handlebars' in your project.
error TypeError: compile is not a function ↓
cause Default import used instead of named import
fix
Change 'import compile from ...' to 'import { compile } from ...'.
error Error: No template found for type 'handlebars' ↓
cause Legacy type string used without proper configuration
fix
Use type 'oc-template-handlebars' or enable legacy support by setting options.legacy = true.
Warnings
breaking v6.0.0 dropped support for legacy `handlebars` type without explicit configuration. Use `type: 'oc-template-handlebars'` instead. ↓
fix Update component type to 'oc-template-handlebars' or configure legacy support via options.
deprecated The `getInfo` export is deprecated as of v6.5.0. It may be removed in a future major version. ↓
fix Avoid using `getInfo`; rely on other OC APIs for version info.
gotcha The `compile` function requires a Handlebars instance to be passed in options. Omitting it will throw a runtime error. ↓
fix Always pass handlebars: require('handlebars') in the options object to compile().
gotcha ESM imports are supported but the package does not have a 'module' field in package.json; bundlers may need fallback to CommonJS. ↓
fix Ensure your bundler can resolve the main entry (CommonJS) or use a compatible module resolution strategy.
breaking Node.js <12 is no longer supported since v6.0.0. Handlebars 4.x is required. ↓
fix Upgrade Node.js to >=12 and ensure handlebars >=4.0.0 is installed.
Install
npm install oc-template-handlebars-compiler yarn add oc-template-handlebars-compiler pnpm add oc-template-handlebars-compiler Imports
- compile wrong
import compile from 'oc-template-handlebars-compiler'correctimport { compile } from 'oc-template-handlebars-compiler' - getInfo wrong
const getInfo = require('oc-template-handlebars-compiler').getInfocorrectimport { getInfo } from 'oc-template-handlebars-compiler' - oc-template-handlebars-compiler type wrong
import { CompilerOptions } from 'oc-template-handlebars-compiler'correctimport type { CompilerOptions } from 'oc-template-handlebars-compiler'
Quickstart
import { compile } from 'oc-template-handlebars-compiler';
import { getInfo } from 'oc-template-handlebars-compiler';
const template = '<div>{{message}}</div>';
const info = getInfo();
console.log('Compiler info:', info);
const compiled = compile(template, { type: 'oc-template-handlebars' }, {
version: '6.0.0',
handlebars: require('handlebars')
});
console.log('Compiled component:', compiled);