Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.84k stars 598 forks source link

Can't import with webpack #629

Open GameCodingNinja opened 2 years ago

GameCodingNinja commented 2 years ago

Installed... npm install xml2js npm install @types/xml2js

Trying to add it to a project...

import * as xml2js from 'xml2js';

... throws a bunch of errors. SAX is installed.

asset bundle.js 1.47 MiB [compared for emit] [big] (name: main) runtime modules 937 bytes 4 modules modules by path ../ 1.23 MiB modules by path ../library/ 550 KiB 106 modules modules by path ../node_modules/ 715 KiB modules by path ../node_modules/planck-js/lib/ 510 KiB 53 modules modules by path ../node_modules/xmlbuilder/lib/.js 127 KiB 33 modules modules by path ../node_modules/xml2js/lib/.js 20.4 KiB 6 modules 2 modules modules by path ./ 89.1 KiB javascript modules 82.9 KiB modules by path ./source/ 69.5 KiB 15 modules modules by path ./data/objects/ 13.4 KiB 6 modules json modules 6.18 KiB 11 modules

WARNING in ../node_modules/sax/lib/sax.js 163:13-37 Module not found: Error: Can't resolve 'stream' in '/home/howie/Development/javajcript-webgl-game-engine/node_modules/sax/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:

1 warning has detailed information that is not shown. Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

ERROR in ../node_modules/sax/lib/sax.js 233:17-56 Module not found: Error: Can't resolve 'string_decoder' in '/home/howie/Development/javajcript-webgl-game-engine/node_modules/sax/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:

ERROR in ../node_modules/xml2js/lib/parser.js 17:17-47 Module not found: Error: Can't resolve 'timers' in '/home/howie/Development/javajcript-webgl-game-engine/node_modules/xml2js/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:

webpack 5.25.0 compiled with 2 errors and 1 warning in 1189 ms The terminal process "bash '-c', '../node_modules/.bin/webpack --mode none'" terminated with exit code: 1.

JonathanMSifleet commented 2 years ago

I too get this issue, not that it helps

siarheipashkevich commented 1 year ago

@GameCodingNinja @JonathanMSifleet did you fix this issue?

JonathanMSifleet commented 1 year ago

@GameCodingNinja @JonathanMSifleet did you fix this issue?

I ended up using fast-xml-parser instead

ivvitikhonov commented 1 year ago

Webpack 5 no longer polyfills Node.js core modules automatically which means if you use them in your code running in browsers or alike, you will have to install compatible modules from npm and include them yourself.

I have the same problem, but in my case I don't use some functionalities with xml2js and I've decided my problem with update section resolve in webpack.config:


resolve: {
    fallback: { 
        "stream": require.resolve("stream-browserify"),
        "string_decoder": false,
        "buffer": false,
        "events": false
    }
}