{"id":20167,"library":"json5-loader","title":"json5-loader","description":"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.","status":"active","version":"4.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/webpack-contrib/json5-loader","tags":["javascript","webpack"],"install":[{"cmd":"npm install json5-loader","lang":"bash","label":"npm"},{"cmd":"yarn add json5-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add json5-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for loader to function","package":"webpack","optional":false}],"imports":[{"note":"Loader is used in webpack config, not imported directly in source code.","wrong":"const json5Loader = require('json5-loader')","symbol":"json5-loader","correct":"import json5Loader from 'json5-loader'"},{"note":"The `type: 'javascript/auto'` is required to avoid conflicts with webpack 5's default JSON handling.","wrong":"rules: [{ test: /\\.json5$/, loader: 'json5-loader' }]","symbol":"webpack config rule","correct":"rules: [{ test: /\\.json5$/i, loader: 'json5-loader', type: 'javascript/auto' }]"},{"note":"Inline loader syntax is supported but configuration-based usage is recommended for clarity.","wrong":"const data = require('./file.json5')","symbol":"inline require","correct":"const data = require('json5-loader!./file.json5')"}],"quickstart":{"code":"// file.json5\n{\n  env: 'production',\n  passwordStrength: 'strong',\n}\n\n// webpack.config.js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.json5$/i,\n        loader: 'json5-loader',\n        type: 'javascript/auto',\n      },\n    ],\n  },\n};\n\n// index.js\nimport appConfig from './file.json5';\nconsole.log(appConfig.env); // 'production'","lang":"javascript","description":"Shows how to configure webpack to load JSON5 files with json5-loader and import the parsed object."},"warnings":[{"fix":"Upgrade Node.js to version >= 10.13.0","message":"Node.js version < 10.13.0 is no longer supported","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Set `esModule: false` in loader options if you need CommonJS output","message":"ES module syntax is used by default (esModule: true) since v4.0.0, which may break CommonJS bundles","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Upgrade Node.js or use earlier loader version","message":"Minimum required Node.js version is 8.9.0 for v3.0.0","severity":"breaking","affected_versions":">=3.0.0 <4.0.0"},{"fix":"Add `type: 'javascript/auto'` to the loader rule","message":"Missing `type: 'javascript/auto'` in webpack rule causes issues with webpack 5's default JSON handling","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Use configuration-based rules instead of inline loader syntax","message":"await import() with inline loader syntax may not work in webpack 5","severity":"deprecated","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add `type: 'javascript/auto'` to the loader rule in webpack.config.js","cause":"Missing `type: 'javascript/auto'` in webpack rule, causing webpack to parse JSON5 as JSON","error":"Module parse failed: Unexpected token (1:5) (The JSON5 file is not being processed)"},{"fix":"Run `npm install json5-loader --save-dev`","cause":"json5-loader is not installed as a devDependency","error":"Cannot find module 'json5-loader'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}