esbuild-plugin-yaml-import
raw JSON → 0.1.1 verified Fri May 01 auth: no javascript
An esbuild plugin that allows importing YAML files directly in your code. Version 0.1.1, maintained by linbudu599. It uses JS-YAML under the hood to parse YAML content into JSON, then leverages esbuild's built-in JSON loader. Key differentiators: simple setup, minimal configuration, support for transforming content before or after parsing, and TypeScript type declarations. Suitable for small to medium projects needing YAML import capability in esbuild. Release cadence is low; last update was a while ago. Compared to alternatives like 'esbuild-plugin-yaml', it offers transform hooks and direct JS-YAML configuration.
Common errors
error Error: Cannot find module 'esbuild-plugin-yaml-import' ↓
cause Package not installed or not in node_modules.
fix
Run npm install esbuild-plugin-yaml-import --save-dev
error TypeError: yaml is not a function ↓
cause Importing the plugin incorrectly (e.g., named import instead of default).
fix
Use import yaml from 'esbuild-plugin-yaml-import'
error Build failed with error: Unexpected token ':' in file '...' ↓
cause YAML file is malformed or has invalid syntax.
fix
Validate YAML content with a linter.
Warnings
gotcha Plugin only works with '.yaml' and '.yml' file extensions. Other YAML-like extensions are not recognized. ↓
fix Ensure your YAML files have .yaml or .yml extension.
gotcha When using transformContent or transformParsed options, be aware that async functions are not supported; they must be synchronous. ↓
fix Use synchronous transformations only.
gotcha If esbuild version is less than ^0.11.19, the plugin may fail due to API incompatibility. ↓
fix Update esbuild to version 0.11.19 or later.
Install
npm install esbuild-plugin-yaml-import yarn add esbuild-plugin-yaml-import pnpm add esbuild-plugin-yaml-import Imports
- default (or yaml plugin function) wrong
import { yaml } from 'esbuild-plugin-yaml-import'correctimport yaml from 'esbuild-plugin-yaml-import' - Options type
import type { Options } from 'esbuild-plugin-yaml-import' - CommonJS require wrong
const { yaml } = require('esbuild-plugin-yaml-import')correctconst yaml = require('esbuild-plugin-yaml-import')
Quickstart
import { build } from 'esbuild';
import yamlPlugin from 'esbuild-plugin-yaml-import';
// Sample YAML file: config.yaml
// name: John
// age: 30
build({
entryPoints: ['src/index.ts'],
bundle: true,
outfile: 'dist/bundle.js',
plugins: [yamlPlugin()],
}).catch(() => process.exit(1));