esbuild-plugin-yaml
raw JSON → 0.0.1 verified Fri May 01 auth: no javascript
An esbuild plugin that allows importing YAML files as ES6 modules, converting YAML content into JavaScript objects at build time. Currently at version 0.0.1, it relies on js-yaml for parsing and provides options for custom load options and a transformation hook. Minor updates expected; alternative to other JSON/YAML esbuild plugins with a focus on simplicity and TypeScript support.
Common errors
error Cannot find module 'esbuild-plugin-yaml' ↓
cause Package not installed or not in node_modules; or project is using a different package manager (yarn vs npm) and cache is stale.
fix
Run
npm install esbuild-plugin-yaml or yarn add esbuild-plugin-yaml and ensure your lock file is updated. error TypeError: yamlPlugin is not a function ↓
cause yamlPlugin is imported incorrectly (e.g., default import instead of named import) or the package version is very old (though 0.0.1 only).
fix
Change import to: import { yamlPlugin } from 'esbuild-plugin-yaml';
error error: No loader is configured for ".yaml" files ↓
cause Esbuild's default loaders do not include YAML; the plugin's loader may not have been applied properly (e.g., plugin not included in plugins array).
fix
Ensure the plugin is added to the plugins array: plugins: [yamlPlugin()]. Also check that esbuild version is compatible (>=0.8.0).
Warnings
gotcha Plugin does not automatically resolve .yaml/.yml extensions; esbuild must be configured to handle those file types as data URLs or custom loaders. ↓
fix Ensure esbuild's loader for .yaml/.yml is set to 'file' or use the plugin's internal loader; plugin currently registers a custom loader internally, but may conflict with explicit loader settings.
gotcha Transform option must return an object or undefined; returning a non-object (e.g., string) will cause a runtime error in esbuild. ↓
fix Always return an object or undefined from the transform function. Example: transform(data, filePath) { return { ...data, transformed: true }; }
deprecated The plugin uses CommonJS require in its README example, but the package is ESM-only. The require example will not work. ↓
fix Use import syntax: import { yamlPlugin } from 'esbuild-plugin-yaml'; For CommonJS projects, use dynamic import: const { yamlPlugin } = await import('esbuild-plugin-yaml');
Install
npm install esbuild-plugin-yaml yarn add esbuild-plugin-yaml pnpm add esbuild-plugin-yaml Imports
- yamlPlugin wrong
const yamlPlugin = require('esbuild-plugin-yaml')correctimport { yamlPlugin } from 'esbuild-plugin-yaml' - default wrong
import { default as yamlPlugin } from 'esbuild-plugin-yaml'correctimport yamlPlugin from 'esbuild-plugin-yaml' - type YAMLOptions wrong
import { YAMLOptions } from 'esbuild-plugin-yaml'correctimport type { YAMLOptions } from 'esbuild-plugin-yaml'
Quickstart
import esbuild from 'esbuild';
import { yamlPlugin } from 'esbuild-plugin-yaml';
await esbuild.build({
entryPoints: ['src/index.ts'],
bundle: true,
outfile: 'dist/bundle.js',
plugins: [yamlPlugin()]
});
// Then in your code:
// import config from './config.yaml';
// console.log(config);