json-schema-ref-parser icon indicating copy to clipboard operation
json-schema-ref-parser copied to clipboard

Improve compatibility with browser by using better APIs

Open fregante opened this issue 3 years ago • 2 comments

The browser compatibility claimed by this package is only due to bundlers’ polyfills, which are increasingly missing:

  • https://github.com/APIDevTools/json-schema-ref-parser/issues/257
  • https://github.com/APIDevTools/json-schema-ref-parser/issues/254
  • https://github.com/JS-DevTools/ono/issues/17
  • https://github.com/APIDevTools/json-schema-ref-parser/issues/137
  • https://github.com/APIDevTools/json-schema-ref-parser/issues/267
  • https://github.com/APIDevTools/json-schema-ref-parser/blob/5d7f89527ea773cdd37583a3c7ab91ee3b1db5a9/lib/util/url.js#L25-L26
  • https://github.com/APIDevTools/json-schema-ref-parser/blob/ce236698d79b29ebddd49722a50d0dd1fdc140ff/lib/util/url.js#L3

http and https can be replaced by fetch, which is available in Node 18 and can already be used everywhere with https://github.com/matthew-andrews/isomorphic-fetch. I think this would also avoid Buffer issues

URLs can be parsed with the URL constructor, available globally in Node 10.

They can all be replaced by their modern and cross-platform equivalents or they can use something like globalThis.process?.platform to ensure that they don't immediately fail when missing.

fregante avatar Jul 30 '22 11:07 fregante

Thank you, this makes for a great Epic for folks to work from.

If anyone can take a swing at knocking out a few of these that sounds be hugely helpful.

philsturgeon avatar Jul 30 '22 20:07 philsturgeon

Maybe this will help: https://stackblitz.com/edit/webpack-webpack-js-org-vcdpkp?file=src/index.js

cihad avatar Sep 23 '22 22:09 cihad

I've taken it, please wait for the PR when the Hacktoberfest starts :smile:

alanpoulain avatar Sep 27 '22 13:09 alanpoulain

it seems node-fetch dependency recreate this issue. How to compile it now for browsers in webpack ?

node-fetch is importing node:http instead of http, node"fs instead of fs, .... So all webapck classiuc NodePolyfills are no more working

paztis avatar Nov 15 '23 09:11 paztis