Open vtrushin opened 6 years ago
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?
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.
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.
emmm, how about React Native bundling? i have to decode xml on my React Native App, what should i do?
ooops, i found https://www.npmjs.com/package/react-native-xml2js to resolve my problem. 😂
any progress?
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).
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 this package is too old,could error。
From README:
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)