{"id":20876,"library":"xml-loader","title":"Webpack XML Loader","description":"A webpack loader that converts XML files into JSON objects using node-xml2js. Current stable version is 1.2.1. It supports query-string options to configure the xml2js parser, such as explicitChildren, and can be used both inline and via webpack config. Maintained as a simple, focused loader for webpack 1-4; does not support webpack 5 by default. Alternatives include raw-loader or custom loaders for more modern webpack setups.","status":"maintenance","version":"1.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/gisikw/xml-loader","tags":["javascript","webpack","loader","xml"],"install":[{"cmd":"npm install xml-loader","lang":"bash","label":"npm"},{"cmd":"yarn add xml-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add xml-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Parses XML to JSON; loader delegates all parsing to this library.","package":"node-xml2js","optional":false},{"reason":"Peer dependency; loader is designed to be used with webpack.","package":"webpack","optional":false}],"imports":[{"note":"The loader returns the default export as a JSON object, not a named export.","wrong":"import { data } from 'xml-loader!./data.xml'","symbol":"default","correct":"import data from 'xml-loader!./data.xml'"},{"note":"Do not use !xml-loader — the ! prefix disables loaders. Use xml-loader! instead.","wrong":"const data = require('!xml-loader!./data.xml');","symbol":"require","correct":"const data = require('xml-loader!./data.xml');"},{"note":"Since webpack 2+, use `rules` and `use` instead of deprecated `loaders` and `loader`.","wrong":"module.exports = { module: { loaders: [ { test: /\\.xml$/, loader: 'xml-loader' } ] } };","symbol":"webpack config","correct":"module.exports = { module: { rules: [ { test: /\\.xml$/, use: 'xml-loader' } ] } };"},{"note":"Query parameters should be placed before the file, not after.","wrong":"require('xml-loader!./data.xml?explicitChildren=true')","symbol":"query params","correct":"require('xml-loader?explicitChildren=true!./data.xml')"}],"quickstart":{"code":"// webpack.config.js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.xml$/,\n        use: 'xml-loader'\n      }\n    ]\n  }\n};\n\n// app.js\nconst data = require('./data.xml');\nconsole.log(data); // parsed JSON object\n\n// With options\nconst dataWithChildren = require('xml-loader?explicitChildren=true!./data.xml');\nconsole.log(dataWithChildren);","lang":"javascript","description":"Shows how to configure xml-loader in webpack and use it to import an XML file as JSON."},"warnings":[{"fix":"Use a more modern loader or configure with additional module rules.","message":"Webpack 5 compatibility: xml-loader may not work out of the box with webpack 5.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Use { test: /\\.xml$/, use: { loader: 'xml-loader', options: { explicitChildren: true } } }","message":"Query string syntax for loader options is deprecated in webpack 4+. Use `options` object in config instead.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Use raw-loader if you need the raw XML text.","message":"The loader's return value is a JavaScript object, not a string. If you need the raw XML string, use raw-loader.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Configure xml2js options via loader query or options to preserve case.","message":"All XML attributes are coerced to lowercase by default. This may cause breaking changes if you rely on case.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add xml-loader to your webpack config module.rules.","cause":"Webpack cannot parse .xml files without a loader configured.","error":"Module parse failed: Unexpected token (1:0)\nYou may need an appropriate loader to handle this file type."},{"fix":"Run npm install --save-dev xml-loader.","cause":"xml-loader is not installed or not in node_modules.","error":"Error: Cannot find module 'xml-loader'"},{"fix":"Use require('xml-loader!./data.xml') with the full loader name.","cause":"You are using the deprecated ! prefix incorrectly or missing the loader name.","error":"require('xml!./data.xml') returns undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}