xml-js icon indicating copy to clipboard operation
xml-js copied to clipboard

Browser bundling

Open vtrushin opened this issue 6 years ago • 9 comments

From README:

Portable Code: Written purely in JavaScript which means it can be used in Node environment and browser environment (via bundlers like browserify/JSPM/Webpack).

It cannot be fully bundled for browsers because SAX requires Node's built-in packages 'Stream' and 'string_decoder' (https://github.com/isaacs/sax-js/blob/master/lib/sax.js#L233)

vtrushin avatar Mar 12 '18 13:03 vtrushin

Thanks Vlad for this important feedback. I based my assumption on this line on sax project "Designed with node in mind, but should work fine in the browser or other CommonJS implementations." Any idea how to overcome this issue?

nashwaan avatar Mar 12 '18 13:03 nashwaan

You're welcome. And thank you for this project. I use rollup for bundling, and have just found rollup-plugin-node-builtins to resove it. It replaces all node builtins. Maybe it's good solution, expect for Stream, that has really big implementation. But I think, that Stream's require can be ignored for replacing, because it's located in try/catch statement https://github.com/isaacs/sax-js/blob/master/lib/sax.js#L161-L166 and can work w/o it.

vtrushin avatar Mar 12 '18 13:03 vtrushin

These are great findings to share! Thanks. I wonder if there is also a way I can require sax in a fully browser-compatible way so that I don't force the user to manually replace node built-ins.

nashwaan avatar Mar 12 '18 13:03 nashwaan

emmm, how about React Native bundling? i have to decode xml on my React Native App, what should i do?

eczn avatar Dec 11 '18 14:12 eczn

ooops, i found https://www.npmjs.com/package/react-native-xml2js to resolve my problem. 😂

eczn avatar Dec 11 '18 14:12 eczn

any progress?

hengkx avatar Jun 30 '20 03:06 hengkx

Please can this bulletin of the README be amended to reflect this issue as to not mislead anyone else?

Portable Code: Written purely in JavaScript which means it can be used in Node environment and browser environment (via bundlers like browserify/JSPM/Webpack).

james-innes avatar Feb 14 '21 12:02 james-innes

just install npm i stream ✅ https://www.npmjs.com/package/stream

And works.

Update: I move to fast-xml-parser, when bundle with vitejs this lib doesn't work

herberthobregon avatar Sep 08 '21 07:09 herberthobregon

@herberthobregon this package is too old,could error。

SignDawn avatar Nov 02 '21 03:11 SignDawn