Registry / serialization / yaml-loader

yaml-loader

JSON →
library0.9.0jsnpmunverified

A Webpack loader that converts YAML files into JavaScript objects or JSON strings, using the `yaml` library for parsing. The current stable version is 0.9.0, released with support for Webpack 5+ and Node.js 20+. It offers options like `asJSON` for JSON output, `asStream` for parsing multi-document YAML streams, and `namespace` for extracting specific sub-trees. Unlike alternatives like js-yaml-loader, this loader leverages the more modern `yaml` package and is actively maintained. Release cadence is irregular, with major version bumps for breaking changes.

npm install yaml-loader
INSTALL
IMPORT
SIG · YAML-LOADER
Y
yaml-loader
serializationjavascriptv0.9.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

default loader
module.exports = { module: { rules: [ { test: /\.ya?ml$/, use: 'yaml-loader' } ] } }
module.exports = { module: { rules: [ { test: /\.ya?ml$/, loader: 'yaml-loader' } ] } }
When using options, the configuration must use `use` or `loader` with `options` object.
JavaScript import from YAML
import config from './config.yaml';
const config = require('./config.yaml');
ESM import works with Webpack's module bundling; require() may not work in all setups.
TypeScript import (type)
import type { YAMLType } from 'yaml'; // not needed for loader
import yaml from 'yaml'; // yaml is not directly imported by the loader user
The loader itself does not re-export yaml types; use the 'yaml' package directly if type access is needed.
Options with query parameter
import data from './data.yaml?namespace=config';
Query parameters override options set in webpack.config.js.
CommonJS require
const data = require('./data.yaml');
const data = require('yaml-loader!./data.yaml');
Inline loader syntax is discouraged; use Webpack configuration instead.

Configures Webpack to import YAML files as JavaScript objects using yaml-loader.

// webpack.config.js module.exports = { module: { rules: [ { test: /\.ya?ml$/, use: 'yaml-loader', }, ], }, }; // app.js import config from './config.yaml'; console.log(config); // config.yaml server: port: 8080 host: localhost
Debug
Known issues
breakingDrop support for Webpack v4 (#61) and unsupported Node.js versions
fix
Upgrade to Webpack 5 and Node.js 20 or later.
affects: >=0.9.0
breakingOutput JavaScript source by default, rather than JSON (#27)
fix
Set `{ asJSON: true }` option if you need JSON output.
affects: >=0.7.0
breakingReplace `js-yaml` dependency with `yaml`
fix
Some YAML files parsed as valid by js-yaml may now be invalid; review your YAML files and update if needed.
affects: >=0.6.0
breakingDrop output JSON prettification
fix
Output is no longer multiline or tab-indented; if you need prettified JSON, chain another loader or use `asJSON` option and format yourself.
affects: >=0.6.0
deprecatedNode.js versions below 12.13 are no longer supported
fix
Upgrade Node.js to at least 12.13.
affects: >=0.8.0
gotchaOptions set in webpack.config.js via `options` object are superseded by query parameters (`?namespace=...`)
fix
Use either `options` in config or query parameters, not both, to avoid confusion.
affects: all
gotchaThe `asStream` option always outputs an array and ignores `namespace`
fix
Do not combine `asStream` with `namespace`; they are mutually exclusive.
affects: >=0.6.0
Errors
Common errors & fixes
Module parse failed: Unexpected token (1:2)
Webpack is trying to parse a YAML file without the yaml-loader configured.
fix
Add module rule in webpack.config.js: { test: /\.ya?ml$/, use: 'yaml-loader' }
Error: Cannot find module 'yaml'
The 'yaml' package is not installed.
fix
Run: npm install --save-dev yaml
Critical dependency: the request of a dependency is an expression
Using inline loader syntax like `require('yaml-loader!./file.yaml')` with dynamic path.
fix
Configure the loader in webpack.config.js and use static imports instead.
yaml-loader: options are not allowed for this loader (use 'use' instead of 'loader' with options)
Passing options with `loader` key directly instead of inside `use`.
fix
Use: { use: { loader: 'yaml-loader', options: { asJSON: true } } }
Upgrade
Version history
0.9.0latest on npm
Audit
Dependencies
webpackrequiredpeer dependency; loader is designed to work with Webpack 5+
yamlrequiredused internally for parsing YAML files
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
1
Resources