extractus / feed-extractor

Simplest way to read & normalize RSS/ATOM/JSON feed data
https://extractor-demos.pages.dev/feed-extractor
MIT License
164 stars 33 forks source link

Commit causing Buffer error when executing in browser, not Node environment #133

Open willjstevens opened 5 months ago

willjstevens commented 5 months ago

This commit (line 36 in retrieve.js) breaks the extract call is giving the following error when executing in a browser such as Chrome:

Uncaught (in promise) ReferenceError: Buffer is not defined at __WEBPACK_DEFAULT_EXPORT__ (retrieve.js:58:1) at async extract

Screenshot 2024-05-18 at 3 19 16 PM

The reason is that Buffer object is only available in a Node environment, not in a browser library.

You either want to rewrite it to not depend on that Node Buffer class or rewrite the line something like:

const text = (buffer && Buffer) ? Buffer.from(buffer).toString().trim() : ''

ndaidong commented 5 months ago

@willjstevens this library's browser support is quite limited, making it nearly unusable in that environment. Considering this, would it be best to remove browser compatibility from the project's scope for now?

willjstevens commented 5 months ago

Well, I have been using it in the browser for testing and analysis, in addition to a backend-Node environment. Limiting it to Node only would only inhibit from other use cases; might cause people to go elsewhere. This is also a JavaScript library and theoretically, anything written in JavaScript should function in any JavaScript engine (browser or Node.) Requiring Node, if anything, could be handled by externalizing Node-only components to external module, over marking as Node only. This would give people choice of how to use it.

This library is nice and is useful. I recommend not limiting it. Just try to rewrite the line above. Or ask, 'is that Buffer optimization necessary?' Or how could it be handled differently?, etc. BTW - thanks for your work on this helpful project.

ndaidong commented 5 months ago

@willjstevens ok, let me see how we should deal with buffer at the client side.

melkikh commented 3 months ago

+1, Buffer API isn't available in Cloudflare Workers. So, I can't use the latest version of the package.

freetonik commented 1 month ago

+1, Buffer API isn't available in Cloudflare Workers. So, I can't use the latest version of the package.

@melkikh Cloudflare just rolled out a new update to Node runtime compatibility for Workers, and Buffer is now available. See https://blog.cloudflare.com/more-npm-packages-on-cloudflare-workers-combining-polyfills-and-native-code/

I'm using the latest version there, and it works, but you have to update your wrangler.toml with:

compatibility_flags = ["nodejs_compat"]
compatibility_date = "2024-09-23"