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
muslnode 18–226 runs
build_error
glibcnode 18–226 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);
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.
fixAdd 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.
fixRun: 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.
fixEnsure js-yaml version 3.x is installed (npm install js-yaml@3)
Audit
Dependencies
js-yamloptionalPeerdependency for YAML parsing