Skip to content
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

Pushy.register() fails attempting to use fetch #2

Closed
chasegiunta opened this issue May 12, 2020 · 3 comments
Closed

Pushy.register() fails attempting to use fetch #2

chasegiunta opened this issue May 12, 2020 · 3 comments

Comments

@chasegiunta
Copy link

Error: The API request failed: fetch is not a function
    at Object.register (webpack:///./node_modules/pushy-electron/lib/Pushy.js?:81:19)
@pushy pushy changed the title Pushy.alert() fails attempting to use fetch Pushy.register() fails attempting to use fetch May 12, 2020
@pushy
Copy link
Owner

pushy commented May 12, 2020

Hi @chasegiunta,
For window.fetch() support in Electron, we're using a dependency node-fetch:
https://www.npmjs.com/package/node-fetch

Seems like your webpack setup is having a hard time processing this dependency. Can you check for any errors arising in webpack?

@chasegiunta
Copy link
Author

Webpack doesn't provide further errors, but it looks like the node-fetch repo is full of issues pertaining to webpack. This seemed to be the most straightforward approach:
node-fetch/node-fetch#450 (comment)

So replacing this line
https://github.com/pushy-me/pushy-electron/blob/1620dbde5f2635350cf10e43131b9cbea78c800e/util/api.js#L1
with const fetch = require('node-fetch').default resolves the issue for me locally, though I'm not sure if there are any other unintended side-effects in non-webpack environments.

Also, looks like version 3 of node-fetch, current in beta, may already have fixed this, but for the time being would it be possible to add .default to the require?

@pushy
Copy link
Owner

pushy commented May 14, 2020

Excellent workaround @chasegiunta, tested and works without webpack as well! 🎉

Committed in b8c0760 and published to npm in 1.0.5. Thanks for your contribution!

@pushy pushy closed this as completed May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants