-
Notifications
You must be signed in to change notification settings - Fork 201
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
Fix illegal invocation errors #47
Conversation
src/index.js
Outdated
@@ -1,4 +1,4 @@ | |||
export default typeof fetch=='function' ? fetch : function(url, options) { | |||
export default typeof fetch == 'function' && typeof window != 'undefined' ? fetch.bind(window) : function(url, options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work if you just do typeof fetch=='function' ? fetch.bind() :
- thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha nice one! 👍
This doesn't fix it for me. Changing it to @developit would you be open for a PR that changes it to explicitly bind it to |
Never mind. It is possible to fix it in the Webpack config without updating
|
How are you testing that it didn't work @balloob? |
Sorry, it's in a private repo at work so don't have a minimal work around. Was using Webpack 3.1 and Unfetch 3.0. When I changed Can take a stab on Monday to get a minimal repro. |
That would be good - I was testing in Safari and |
I was testing it in Chrome. |
@developit @balloob I'm using isomorphic-unfetch, confirming that i still get this error on chrome. Edit: works just fine on safari. |
Hmm - can you try this in your console and tell me if it fails? let unfetch = fetch.bind();
unfetch('/').then(console.log) Works for me in Chrome 59+ |
@developit No errors when i run the snippet in chrome console. As @balloob was mentioning, issue happens within the app only when i bundle with webpack 3.1 and run the app on chrome. Fyi I'm on chrome 60 beta version. |
One thing I just thought of - Function.prototype.bind is IE9+ |
Fixes #46
I can also confirm the fix in my local setup.