Please describe the problem you are having in as much detail as possible:
Alright! Here we go. When I try to run my bot using the ShardingManager, I get this (linkified for reference):
(node:20052) UnhandledPromiseRejectionWarning: TypeError: fetch is not a function
at Function.fetchRecommendedShards
at ShardingManager.spawn
Note that node-fetch is imported correctly, as recommended by the node-fetch docs.
Include a reproducible code sample here, if possible:
My bot's open source. Here's the branch where I'm working on the update. The readme describes how to configure and provides a minimum viable configuration.
Further details:
Here's where I asked about this problem in the Discord... not that I got anything out of it.
This is why you don't use webpack for the backend, it has no purpose but makes everything a tad more complicated.
node-fetch, when used with webpack, just boils down to this https://github.com/bitinn/node-fetch/blob/master/browser.js
Fetch not being a global thing outside of browsers makes this whole thing blow up.
Edit:
There seems to be a workaround, but it would require using the default export in our code-base to alleviate webpack issues.
I don't see the point in doing this, esp if you are using Typescript there is no need to use webpack at all for your backend code, its utter nonsense.
I use webpack because I build to deploy via Docker. This is a recent thing - it was working (and still is, using the same settings) on the 11.5.1 release on NPM.
You don't need webpack to deploy via Docker, if you would no one would use Docker.
Regardless of that, stable does not use node-fetch, it uses snekfetch a now deprecated http library.
I wouldn't consider a year, relatively "recent" either. #2587
"Last publish: 5 months ago."
I use webpack because I want to minimize image size. Regardless, in my config, Webpack is setup to build for Node targets.
The last publish of the v11 version, which is not what the master branch reflects.
The master branch is v12 with quite a few breaking changes, nothing to do with the last publish.
Again, this is a webpack issue. From researching this is the only thing I found that could help alleviate the problem on your side:
https://github.com/bitinn/node-fetch/issues/450#issuecomment-494475397
Ah. Thanks!
Most helpful comment
This is why you don't use webpack for the backend, it has no purpose but makes everything a tad more complicated.
node-fetch, when used with webpack, just boils down to this https://github.com/bitinn/node-fetch/blob/master/browser.js
Fetch not being a global thing outside of browsers makes this whole thing blow up.
Edit:
There seems to be a workaround, but it would require using the default export in our code-base to alleviate webpack issues.
I don't see the point in doing this, esp if you are using Typescript there is no need to use webpack at all for your backend code, its utter nonsense.