fetch: Fetch breaks with update to 3.0.0
It seems, that after updating the build to rollup, the code is not transpiled correctly for IE11. We are recieving this error.
SCRIPT1002: Wrong syntax
File: fetch-polyfill.js, row: 87, column: 1
The fetch-polyfill.js includes the fetch.js file from your repository.
This is where it fails:
export function Headers(headers) { // row 87
this.map = {}
if (headers instanceof Headers) {
headers.forEach(function(value, name) {
this.append(name, value)
}, this)
} else if (Array.isArray(headers)) {
headers.forEach(function(header) {
this.append(header[0], header[1])
}, this)
} else if (headers) {
Object.getOwnPropertyNames(headers).forEach(function(name) {
this.append(name, headers[name])
}, this)
}
}
export function syntax is not supported in IE11
Version: 3.0.0 OS: Linux, Windows
Version 2.0.4 works fine for us.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 23 (4 by maintainers)
Commits related to this issue
- ReferenceError: fetch is not defined when usd fetch polyfill v3.0.0 Issue https://github.com/github/fetch/issues/656 workaround — committed to laukstein/lea.laukstein.com by laukstein 6 years ago
Yes,
fetch.jsfile now has the ES6exportsyntax and will not be compatible with many browsers. This is why we build the UMD dist file and point to it from this package’smainproperty, while themoduleproperty points tofetch.js.The solution is to respect the
mainproperty from this package instead of loading thefetch.jsfile directly. The file reorganization and UMD introduction was the main reason for the major version bump to v3.With the new release, it looks like you need to pull the
umdversion from thedistfolder.Here’s one possible way:
(Also this does seem an odd choice for a polyfill. Do any browsers actually exist that need a fetch polyfill and can do ES6? I don’t understand what targets or use-cases an ES6 fetch polyfill is serving, but that just may be my lack of contemporary JS expertise. For me, not being an expert, it makes it somewhat more complicated to figure out how to properly deliver this polyfill to browsers that actually need it.)
How can this be used correctly via a CDN?
@jakob-e For sure; if I knew how many cascading failures would the 3.0 release cause, I would have done this more carefully. 😣 However, I still don’t believe that our team is responsible for actually fixing most of those failures. Too many people and scripts have hardcoded loading the
whatwg-fetch/fetch.jsfile in their apps instead of parsing thewhatwg-fetch/package.jsonproperly, and they will have to either:As for the CDN problem, here is what we (the maintainer team) don’t have to do to fix it:
exportstatements. We ship an ES module with our package now, and removing thoseexports would break the module.What CDNs should do to fix this:
package.jsonof whatwg-fetch to determine the file referenced by themainproperty, and serve that to browsers.I’m closing this now because there’s not anything actionable for us to do to address the issues people have been having in this thread. If I have missed something, please let me know!
Is
fetch.umd.jsfile supposed to be on the bower package ? Because it is not…