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.
Common errors
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
Warnings
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
Install
npm install refs-compiler yarn add refs-compiler pnpm add refs-compiler Imports
- default wrong
const compiler = require('refs-compiler')correctimport compiler from 'refs-compiler' - compiler wrong
import { compiler } from 'refs-compiler'correctimport compiler from 'refs-compiler' - default (via CommonJS) wrong
const compiler = require('refs-compiler')correctconst { default: compiler } = require('refs-compiler')
Quickstart
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}`);
}