rollup-plugin-handlebars

raw JSON →
1.0.0 verified Mon Apr 27 auth: no javascript abandoned

A Rollup plugin that compiles Handlebars templates (.hbs) to JavaScript functions during the bundling process. Version 1.0.0 is the latest stable release, published only once in 2017. It allows importing .hbs files directly as template functions, with support for Handlebars compile options. Key limitation: no longer maintained, incompatible with modern Rollup v2+, and no TypeScript support.

error Error: No plugin known for extension: .hbs
cause Plugin not installed or not included in rollup config.
fix
Add import handlebars from 'rollup-plugin-handlebars' and include in plugins array.
error Error: Cannot find module 'rollup-plugin-handlebars'
cause Package not installed.
fix
Run npm install rollup-plugin-handlebars --save-dev (or yarn equivalent).
error Error: 'default' is not exported by rollup-plugin-handlebars
cause Named import used instead of default import.
fix
Use import handlebars from 'rollup-plugin-handlebars'; (without curly braces).
breaking Plugin only supports Rollup v0.x (pre-1.0). Not compatible with rollup >= 1.0 due to plugin API changes.
fix Switch to @rollup/plugin-handlebars or use a different plugin.
gotcha Handlebars runtime must be present in final bundle. Templates compile to functions that call Handlebars.runtime functions.
fix Ensure handlebars is installed as a dependency (not devDependency) or externalize the runtime.
deprecated Plugin uses deprecated rollup-pluginutils package. Future Rollup breaking changes may cause failures.
fix Migrate to an alternative that doesn't depend on rollup-pluginutils.
npm install rollup-plugin-handlebars
yarn add rollup-plugin-handlebars
pnpm add rollup-plugin-handlebars

Demonstrates Rollup config with handlebars plugin and importing .hbs template as compiled function.

// rollup.config.js
import handlebars from 'rollup-plugin-handlebars';

export default {
  input: 'src/index.js',
  output: {
    dir: 'dist',
    format: 'cjs'
  },
  plugins: [
    handlebars()
  ]
};

// src/template.hbs
<h1>{{title}}</h1>

// src/index.js
import tmpl from './template.hbs';
console.log(tmpl({ title: 'Hello' }));