Registry / serialization / js-yaml-loader

js-yaml-loader

JSON →
library1.2.2jsnpmunverified

A Webpack loader that transpiles YAML files into JavaScript objects using js-yaml. Version 1.2.2 (latest) is stable with no active development since 2019. Unlike yaml-loader which outputs JSON, this loader supports YAML types disallowed in JSON (e.g., Infinity, RegExp, Function) via js-yaml's load. Options include safe load (default true) and iterator for multi-document YAML. Compatible with Webpack 4+.

npm install js-yaml-loader
INSTALL
IMPORT
SIG · JS-YAML-LOADER
J
js-yaml-loader
serializationjavascriptv1.2.2
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

default (loader)
import doc from 'js-yaml-loader!./file.yml'
require('js-yaml-loader!./file.yml')
Inline loader syntax with import is the expected usage.
config rule
module.exports = { module: { rules: [{ test: /\.yaml$/, use: 'js-yaml-loader' }] } }
module.exports = { module: { loaders: [{ test: /\.yaml$/, loader: 'js-yaml-loader' }] } }
Use 'use' and 'rules' in Webpack 4+. 'loaders' is deprecated.
options
module.exports = { module: { rules: [{ test: /\.yaml$/, use: { loader: 'js-yaml-loader', options: { safe: false } } }] } }
module.exports = { module: { rules: [{ test: /\.yaml$/, loader: 'js-yaml-loader?safe=false' }] } }
Pass options as object in Webpack 4+; query string syntax works but is less flexible.

Configures Webpack to import YAML files as JavaScript objects with safe loading by default.

// webpack.config.js module.exports = { module: { rules: [ { test: /\.(yaml|yml)$/, use: [ { loader: 'js-yaml-loader', options: { safe: true } // default, prevents unsafe types } ] } ] } }; // In your source file: import config from './config.yaml'; console.log(config.database.host);
Debug
Known issues
gotchasafeLoad is used by default, which disables unsafe YAML types (RegExp, Function, undefined). Set safe: false to allow them.
fix
Add option { safe: false } to loader configuration or inline query: js-yaml-loader?safe=false
affects: >=1.0.0
gotchaThis loader outputs JavaScript objects, not JSON. If you expect a JSON string, use yaml-loader instead.
fix
Use yaml-loader if JSON output is needed.
affects: >=1.0.0
gotchaThe package is in maintenance mode; no updates since 2019. Consider alternatives for Webpack 5+ compatibility.
fix
Test with Webpack 5 or migrate to yaml-loader or custom loader.
affects: >=1.0.0
Errors
Common errors & fixes
Module parse failed: Unexpected token (1:1) You may need an appropriate loader to handle this file type.
Webpack cannot parse YAML files because the loader rule is missing or misconfigured.
fix
Add a rule for .yaml files using js-yaml-loader: { test: /\.yaml$/, use: 'js-yaml-loader' }
Error: Cannot find module 'js-yaml'
js-yaml is a peer dependency and must be installed separately.
fix
Run: npm install js-yaml
TypeError: (0 , _jsYaml.safeLoad) is not a function
The js-yaml package version is too old or incompatible; safeLoad was renamed in js-yaml v4.
fix
Ensure js-yaml version 3.x is installed (npm install js-yaml@3)
Upgrade
Version history
1.2.2latest on npm
Audit
Dependencies
js-yamloptionalPeerdependency for YAML parsing
Agent activity
12 hits · last 30 days
node
12
Resources
js-yaml-loader — npm install js-yaml-loader · libregistry