node-xml2js icon indicating copy to clipboard operation
node-xml2js copied to clipboard

Can't import with webpack

Open GameCodingNinja opened this issue 3 years ago • 4 comments

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: - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }' - install 'stream-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "stream": false } @ ../node_modules/xml2js/lib/parser.js 9:8-22 @ ../node_modules/xml2js/lib/xml2js.js 12:11-30 @ ./source/state/startupstate.js 51:0-33 62:8-26 @ ./source/game/game.js 14:0-53 96:29-41 @ ./source/game/main.js 9:0-33 12:15-19

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: - add a fallback 'resolve.fallback: { "string_decoder": require.resolve("string_decoder/") }' - install 'string_decoder' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "string_decoder": false } resolve 'string_decoder' in '/home/howie/Development/javajcript-webgl-game-engine/node_modules/sax/lib' Parsed request is a module using description file: /home/howie/Development/javajcript-webgl-game-engine/node_modules/sax/package.json (relative path: ./lib) Field 'browser' doesn't contain a valid alias configuration resolve as module /home/howie/Development/javajcript-webgl-game-engine/node_modules/sax/lib/node_modules doesn't exist or is not a directory /home/howie/Development/javajcript-webgl-game-engine/node_modules/sax/node_modules doesn't exist or is not a directory /home/howie/Development/javajcript-webgl-game-engine/node_modules/node_modules doesn't exist or is not a directory looking for modules in /home/howie/Development/javajcript-webgl-game-engine/node_modules single file module using description file: /home/howie/Development/javajcript-webgl-game-engine/package.json (relative path: ./node_modules/string_decoder) no extension Field 'browser' doesn't contain a valid alias configuration /home/howie/Development/javajcript-webgl-game-engine/node_modules/string_decoder doesn't exist .js Field 'browser' doesn't contain a valid alias configuration /home/howie/Development/javajcript-webgl-game-engine/node_modules/string_decoder.js doesn't exist .json Field 'browser' doesn't contain a valid alias configuration /home/howie/Development/javajcript-webgl-game-engine/node_modules/string_decoder.json doesn't exist .wasm Field 'browser' doesn't contain a valid alias configuration /home/howie/Development/javajcript-webgl-game-engine/node_modules/string_decoder.wasm doesn't exist /home/howie/Development/javajcript-webgl-game-engine/node_modules/string_decoder doesn't exist /home/howie/Development/node_modules doesn't exist or is not a directory /home/howie/node_modules doesn't exist or is not a directory /home/node_modules doesn't exist or is not a directory /node_modules doesn't exist or is not a directory @ ../node_modules/xml2js/lib/parser.js 9:8-22 @ ../node_modules/xml2js/lib/xml2js.js 12:11-30 @ ./source/state/startupstate.js 51:0-33 62:8-26 @ ./source/game/game.js 14:0-53 96:29-41 @ ./source/game/main.js 9:0-33 12:15-19

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: - add a fallback 'resolve.fallback: { "timers": require.resolve("timers-browserify") }' - install 'timers-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "timers": false } resolve 'timers' in '/home/howie/Development/javajcript-webgl-game-engine/node_modules/xml2js/lib' Parsed request is a module using description file: /home/howie/Development/javajcript-webgl-game-engine/node_modules/xml2js/package.json (relative path: ./lib) Field 'browser' doesn't contain a valid alias configuration resolve as module /home/howie/Development/javajcript-webgl-game-engine/node_modules/xml2js/lib/node_modules doesn't exist or is not a directory /home/howie/Development/javajcript-webgl-game-engine/node_modules/xml2js/node_modules doesn't exist or is not a directory /home/howie/Development/javajcript-webgl-game-engine/node_modules/node_modules doesn't exist or is not a directory looking for modules in /home/howie/Development/javajcript-webgl-game-engine/node_modules single file module using description file: /home/howie/Development/javajcript-webgl-game-engine/package.json (relative path: ./node_modules/timers) no extension Field 'browser' doesn't contain a valid alias configuration /home/howie/Development/javajcript-webgl-game-engine/node_modules/timers doesn't exist .js Field 'browser' doesn't contain a valid alias configuration /home/howie/Development/javajcript-webgl-game-engine/node_modules/timers.js doesn't exist .json Field 'browser' doesn't contain a valid alias configuration /home/howie/Development/javajcript-webgl-game-engine/node_modules/timers.json doesn't exist .wasm Field 'browser' doesn't contain a valid alias configuration /home/howie/Development/javajcript-webgl-game-engine/node_modules/timers.wasm doesn't exist /home/howie/Development/javajcript-webgl-game-engine/node_modules/timers doesn't exist /home/howie/Development/node_modules doesn't exist or is not a directory /home/howie/node_modules doesn't exist or is not a directory /home/node_modules doesn't exist or is not a directory /node_modules doesn't exist or is not a directory @ ../node_modules/xml2js/lib/xml2js.js 12:11-30 @ ./source/state/startupstate.js 51:0-33 62:8-26 @ ./source/game/game.js 14:0-53 96:29-41 @ ./source/game/main.js 9:0-33 12:15-19

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.

GameCodingNinja avatar Sep 02 '21 10:09 GameCodingNinja

I too get this issue, not that it helps

JonathanMSifleet avatar Jan 01 '22 17:01 JonathanMSifleet

@GameCodingNinja @JonathanMSifleet did you fix this issue?

siarheipashkevich avatar Sep 12 '22 10:09 siarheipashkevich

@GameCodingNinja @JonathanMSifleet did you fix this issue?

I ended up using fast-xml-parser instead

JonathanMSifleet avatar Sep 12 '22 10:09 JonathanMSifleet

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
    }
}

ivvitikhonov avatar May 03 '23 09:05 ivvitikhonov