Spacebars Compiler

raw JSON →
1.6.0 verified Fri May 01 auth: no javascript

Spacebars Compiler compiles Spacebars templates (Handlebars-based syntax used in Meteor) into JavaScript modules compatible with Node.js and browser bundlers. Currently at version 1.6.0. It provides both CLI and programmatic usage for transforming templates into renderable JS functions. Key differentiator: it targets Meteor's Spacebars dialect, not general Handlebars, and supports i18n. Release cadence appears low as the author eface2face maintains it sporadically. Use when migrating Meteor templates to standalone Node/browser apps.

error Cannot find module 'spacebars-compiler'
cause Package not installed or not in node_modules.
fix
Run 'npm install spacebars-compiler' and ensure it's in your dependencies.
error TypeError: compile is not a function
cause Importing the default export incorrectly in CommonJS (require returns an object).
fix
Use const { compile } = require('spacebars-compiler');
error Unexpected identifier: '...'
cause Template contains syntax not valid Spacebars; may be using standard Handlebars helpers.
fix
Validate template strictly against Spacebars grammar.
gotcha The compile function expects Spacebars-specific syntax (e.g., {{#each}}, {{#with}}), not standard Handlebars.
fix Ensure your templates are Meteor Spacebars templates; use a different compiler for Handlebars.
gotcha If using the CLI, ensure the output file path is writable and directories exist.
fix Check file permissions and use --dir to specify an existing directory.
gotcha The package does not ship bundled type definitions; TypeScript users need to provide their own or use @types/spacebars-compiler if available.
fix Add declare module 'spacebars-compiler' or install community typings.
npm install spacebars-compiler
yarn add spacebars-compiler
pnpm add spacebars-compiler

Compile a basic Spacebars template string into a JavaScript function string.

import { compile } from 'spacebars-compiler';
const source = '{{#each items}}<li>{{name}}</li>{{/each}}';
const options = { isBody: true, useGlobalScope: false };
const output = compile(source, options);
console.log(output);