Refs Compiler

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

Compiler for YAML, JSON and INI files using path references. Version 2.0.2 is the latest stable release. The library resolves $ref references in configuration files, enabling modular composition of templates. Designed for Node.js 8+ with native Promises and async/await. Key differentiator: supports YAML, JSON, and INI formats with CLI and programmatic API. Active development with security fixes for js-yaml and handlebars dependencies.

error TypeError: compiler is not a function
cause CommonJS require without accessing .default
fix
const { default: compiler } = require('refs-compiler');
error Cannot find module 'refs-compiler'
cause Package not installed or not in node_modules
fix
Run npm install refs-compiler --save-dev
error SyntaxError: Unexpected token 'export'
cause Using ESM import in a CommonJS environment without transpilation
fix
Use CommonJS require with .default or set type: module in package.json
breaking ESM-only since v2; CommonJS require must use .default
fix Use import compiler from 'refs-compiler' or const { default: compiler } = require('refs-compiler')
deprecated Node.js <8 is not supported
fix Upgrade Node.js to version 8 or higher
gotcha The package uses native Promises; callbacks not supported
fix Use async/await or .then() instead of callbacks
breaking Default export is the compiler function, not an object
fix Do not destructure named exports; import the default export
npm install refs-compiler
yarn add refs-compiler
pnpm add refs-compiler

Resolves $ref references in a YAML template and writes the compiled output to a file.

import path from 'path';
import compiler from 'refs-compiler';

const inputTemplate = path.resolve('/path/to/template.yaml');
const outputFile = path.resolve('/path/to/output.yaml');

try {
  const results = await compiler(inputTemplate, outputFile);
  console.log(`file created in ${results.outputFile}`);
} catch (error) {
  console.error(`An error occurred: ${error.message}`);
}