APIDevTools / json-schema-ref-parser

Parse, Resolve, and Dereference JSON Schema $ref pointers in Node and browsers
https://apitools.dev/json-schema-ref-parser
MIT License
952 stars 227 forks source link

Improve compatibility with browser by using better APIs #275

Closed fregante closed 1 year ago

fregante commented 2 years ago

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

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.

philsturgeon commented 2 years ago

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.

cihad commented 1 year ago

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

alanpoulain commented 1 year ago

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

paztis commented 10 months ago

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