Registry / web-framework / json5-loader

json5-loader

JSON →
library4.0.1jsnpmunverified

A webpack loader for parsing JSON5 files into JavaScript objects. Supports modern JSON5 syntax including comments, trailing commas, and unquoted keys. Current stable version is 4.0.1 (released October 2020), requiring Node.js >= 10.13 and webpack ^4 || ^5. Replaced the built-in json-loader for JSON5 support. Key differentiator: integrates seamlessly with webpack's module system, offering esModule option for ES module output and enabling tree shaking. Maintained by the webpack-contrib organization with regular updates to schema-utils.

npm install json5-loader
INSTALL
IMPORT
SIG · JSON5-LOADER
J
json5-loader
web-frameworkjavascriptv4.0.1
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.

json5-loader
import json5Loader from 'json5-loader'
const json5Loader = require('json5-loader')
Loader is used in webpack config, not imported directly in source code.
webpack config rule
rules: [{ test: /\.json5$/i, loader: 'json5-loader', type: 'javascript/auto' }]
rules: [{ test: /\.json5$/, loader: 'json5-loader' }]
The `type: 'javascript/auto'` is required to avoid conflicts with webpack 5's default JSON handling.
inline require
const data = require('json5-loader!./file.json5')
const data = require('./file.json5')
Inline loader syntax is supported but configuration-based usage is recommended for clarity.

Shows how to configure webpack to load JSON5 files with json5-loader and import the parsed object.

// file.json5 { env: 'production', passwordStrength: 'strong', } // webpack.config.js module.exports = { module: { rules: [ { test: /\.json5$/i, loader: 'json5-loader', type: 'javascript/auto', }, ], }, }; // index.js import appConfig from './file.json5'; console.log(appConfig.env); // 'production'
Debug
Known issues
breakingNode.js version < 10.13.0 is no longer supported
fix
Upgrade Node.js to version >= 10.13.0
affects: >=4.0.0
breakingES module syntax is used by default (esModule: true) since v4.0.0, which may break CommonJS bundles
fix
Set `esModule: false` in loader options if you need CommonJS output
affects: >=4.0.0
breakingMinimum required Node.js version is 8.9.0 for v3.0.0
fix
Upgrade Node.js or use earlier loader version
affects: >=3.0.0 <4.0.0
gotchaMissing `type: 'javascript/auto'` in webpack rule causes issues with webpack 5's default JSON handling
fix
Add `type: 'javascript/auto'` to the loader rule
affects: >=4.0.0
deprecatedawait import() with inline loader syntax may not work in webpack 5
fix
Use configuration-based rules instead of inline loader syntax
affects: >=4.0.0
Errors
Common errors & fixes
Module parse failed: Unexpected token (1:5) (The JSON5 file is not being processed)
Missing `type: 'javascript/auto'` in webpack rule, causing webpack to parse JSON5 as JSON
fix
Add `type: 'javascript/auto'` to the loader rule in webpack.config.js
Cannot find module 'json5-loader'
json5-loader is not installed as a devDependency
fix
Run `npm install json5-loader --save-dev`
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies
webpackrequiredpeer dependency required for loader to function
Agent activity
2 hits · last 30 days
node
2
Resources
json5-loader — npm install json5-loader · libregistry