Registry / serialization / xml-loader

xml-loader

JSON →
library1.2.1jsnpmunverified

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.

npm install xml-loader
INSTALL
IMPORT
SIG · XML-LOADER
X
xml-loader
serializationjavascriptv1.2.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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

default
import data from 'xml-loader!./data.xml'
import { data } from 'xml-loader!./data.xml'
The loader returns the default export as a JSON object, not a named export.
require
const data = require('xml-loader!./data.xml');
const data = require('!xml-loader!./data.xml');
Do not use !xml-loader — the ! prefix disables loaders. Use xml-loader! instead.
webpack config
module.exports = { module: { rules: [ { test: /\.xml$/, use: 'xml-loader' } ] } };
module.exports = { module: { loaders: [ { test: /\.xml$/, loader: 'xml-loader' } ] } };
Since webpack 2+, use `rules` and `use` instead of deprecated `loaders` and `loader`.
query params
require('xml-loader?explicitChildren=true!./data.xml')
require('xml-loader!./data.xml?explicitChildren=true')
Query parameters should be placed before the file, not after.

Shows how to configure xml-loader in webpack and use it to import an XML file as JSON.

// webpack.config.js module.exports = { module: { rules: [ { test: /\.xml$/, use: 'xml-loader' } ] } }; // app.js const data = require('./data.xml'); console.log(data); // parsed JSON object // With options const dataWithChildren = require('xml-loader?explicitChildren=true!./data.xml'); console.log(dataWithChildren);
Debug
Known issues
breakingWebpack 5 compatibility: xml-loader may not work out of the box with webpack 5.
fix
Use a more modern loader or configure with additional module rules.
affects: >=5.0.0
deprecatedQuery string syntax for loader options is deprecated in webpack 4+. Use `options` object in config instead.
fix
Use { test: /\.xml$/, use: { loader: 'xml-loader', options: { explicitChildren: true } } }
affects: >=4.0.0
gotchaThe loader's return value is a JavaScript object, not a string. If you need the raw XML string, use raw-loader.
fix
Use raw-loader if you need the raw XML text.
affects: >=1.0.0
gotchaAll XML attributes are coerced to lowercase by default. This may cause breaking changes if you rely on case.
fix
Configure xml2js options via loader query or options to preserve case.
affects: >=1.0.0
Errors
Common errors & fixes
Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type.
Webpack cannot parse .xml files without a loader configured.
fix
Add xml-loader to your webpack config module.rules.
Error: Cannot find module 'xml-loader'
xml-loader is not installed or not in node_modules.
fix
Run npm install --save-dev xml-loader.
require('xml!./data.xml') returns undefined
You are using the deprecated ! prefix incorrectly or missing the loader name.
fix
Use require('xml-loader!./data.xml') with the full loader name.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
node-xml2jsrequiredParses XML to JSON; loader delegates all parsing to this library.
webpackrequiredPeer dependency; loader is designed to be used with webpack.
Agent activity
21 hits · last 30 days
node
16
OpenAI (training)
1
Resources
xml-loader — npm install xml-loader · libregistry