-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UMD bundled version theoretically should err on browsers without native fetch
support
#1610
Comments
Upon further investigation, I found that {
// ...
"main": "dist/node-ponyfill.js",
"browser": "dist/browser-ponyfill.js",
"react-native": "dist/react-native-ponyfill.js",
"types": "index.d.ts",
// ...
}
{
"name": "cross-fetch-polyfill",
"version": "0.0.0",
"main": "../dist/node-polyfill.js",
"browser": "../dist/browser-polyfill.js",
"react-native": "../dist/react-native-polyfill.js",
"license": "MIT"
} Our // ...
nodeResolve({
mainFields: ['jsnext', 'main'],
preferBuiltins: true,
browser: true,
})
// ... https://github.com/rollup/plugins/tree/master/packages/node-resolve#browser In a built UMD nothing should be left as an On the other hand if we try to bundle the code into the UMD, it can only bundle one of the two exported polyfills, either the node one or the browser one. Currently because of We could still potentially make it work, but then we'd have to bundle I really want to recommend against all of this, the package is already over-complicated in my opinion, and the chances that someone uses this on IE11, or even older Node.js environments is growing slimmer and slimmer by the day, as all of that is EOL. If they want to use older Node.js versions they are welcome to stick to older versions of this package. |
I find it funny that the last maintainer posted on stackoverflow about this problem: https://stackoverflow.com/questions/63594241/how-to-create-umd-bundle-with-fetch-polyfill-rollup-and-typescript . Failed to gauge the exact details of the issue. |
I'm pretty sure that the last paragraph in the installation section refers to the whole project not being UMD compatible: |
The UMD bundled version has the following code in it's http request class:
As far as I know browsers don't implement
require
, it's a Node.js specific module import function. It's supposed to run on IE11 and other decade old end of life browsers/runtimes, but it most probably won't.Testing this with Firefox, Chrome where the check of
if (typeof fetch === 'undefined') {
is commented out, we get a predictable error:Uncaught (in promise) ReferenceError: require is not defined
I am attaching this test file, where I have the UMD file copied into the script tag.
test.zip
While the situation can be mended, I still think it would be best and easiest to drop support for IE11 and target a sensible ES version, and simply drop
cross-fetch
(by the way it generates a warning in Angular meilisearch/meilisearch-js-plugins#1269), the oldest maintained Node.js version supportsfetch
out of the box without any warnings,fetch
is widely supported at this point.The text was updated successfully, but these errors were encountered: