Registry / serialization / esbuild-plugin-yaml

esbuild-plugin-yaml

JSON →
library0.0.1jsnpmunverified

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.

npm install esbuild-plugin-yaml
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-YAM
E
esbuild-plugin-yaml
serializationjavascriptv0.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

yamlPlugin
✓ import { yamlPlugin } from 'esbuild-plugin-yaml'
✗ const yamlPlugin = require('esbuild-plugin-yaml')
Package is ESM-only; require() will fail. Use dynamic import() in CommonJS contexts.
default
✓ import yamlPlugin from 'esbuild-plugin-yaml'
✗ import { default as yamlPlugin } from 'esbuild-plugin-yaml'
Default export is not available; only named export yamlPlugin exists.
type YAMLOptions
✓ import type { YAMLOptions } from 'esbuild-plugin-yaml'
✗ import { YAMLOptions } from 'esbuild-plugin-yaml'
YAMLOptions is only a type export, not a runtime value.

Configure esbuild to import YAML files as ES6 modules using the yamlPlugin.

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);
Debug
Known issues
gotchaPlugin 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.
affects: 0.0.1
gotchaTransform 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 }; }
affects: 0.0.1
deprecatedThe 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');
affects: >=0.0.1
Errors
Common errors & fixes
Cannot find module 'esbuild-plugin-yaml'
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.
TypeError: yamlPlugin is not a function
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: No loader is configured for ".yaml" files
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).
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies
esbuildrequiredpeer dependency — plugin must be used with esbuild
js-yamlrequiredruntime dependency — used to parse YAML files
Agent activity
11 hits · last 30 days
node
10
Resources
esbuild-plugin-yaml — npm install esbuild-plugin-yaml · libregistry