node-fetch: Is there a way to remove "TypeError: Expected signal to be an instanceof AbortSignal"?
https://github.com/node-fetch/node-fetch/blob/master/src/request.js?ts=2#L120
This line causing problem

Let’s check out ths isAbortSignal function

When would it happen?
After Webpack bundle my code, code minification would change the name,
object[NAME] === 'AbortSignal' is not true anymore
so this error would pop up,
The only solution is to turn off code minification
There should be a better way than this
Propose (What to do next)
- Delete this part altogether, don’t check the name
- Don’t compare with string ‘AbortSignal’ like this
object[NAME] === 'AbortSignal', in Ruby we haveclass.nameto get the class name, I am not sure what’s the equivalent in JS
Maybe this StackOverflow question helpful: How to get a JavaScript object’s class?
Thanks
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 10
- Comments: 18 (2 by maintainers)
Commits related to this issue
- Fix AbortSignal from crosis disagreeing with node-fetch node-fetch expects the signal to be an instanceof their signal deferring abort signals for a future feat Solutions proposed here https://github.... — committed to replit/replit-vscode by masad-frost 3 years ago
- Include original error in error message; downgrade to airtable 0.8.1; versions 9.0.0+ fail due to https://github.com/node-fetch/node-fetch/issues/784 — committed to TonyLovesDevOps/airtable-backups-boilerplate by TonyLovesDevOps 3 years ago
- Disable minify This could fix the AbortSignal error. I'm not sure. NodeJS is weird. This shouldn't ever be an issue. What the fuck? Relevant issues: - https://github.com/actions/toolkit/issues/687 ... — committed to diamondburned/cache-install by diamondburned 2 years ago
- [gatsby-plugin-vercel-builder] use --keep-names esbuild flag (#11117) Some packages are very sensitive to minification. For example: https://github.com/node-fetch/node-fetch/issues/784 which ends up... — committed to vercel/vercel by smaeda-ks 5 months ago
- Squashed commit of the following: commit 9a73cbec2c10dce760d15b8421d619bf9ed27ee5 Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Date: Tue Feb 6 19:52:44 2024 +0000 ... — committed to MissLov3ly/vercel by MissLov3ly 5 months ago
For those using esbuild, an equivalent solution to 1c7’s solution is to set the “keepNames” option to true.
https://esbuild.github.io/api/#keep-names
Done, fixed it
Enviroment
Solution:
This can still minify code, but, without mangle with the class name and function name
vue.config.jsResult (This worked)
This is
src/background.jsfile after runningnpm run electron:buildFor comparison (This doesn’t work)
node-fetchwould raise errorFYI if anyone stumbles on this. I get this error in nextjs 14 application with “@azure/storage-blob”: “^12.17.0”: “Blob Upload Error TypeError: Expected signal to be an instanceof AbortSignal”.
To bypass the error you can disable server minification via next.config.js file like this:
WA, which save single name
AbortSignalSource
I couldn’t get the TerserPlugin to work, so I fixed it another way, maybe someone else has a use for this as well. I wrapped the abort signal in the following class: https://gist.github.com/RuurdBijlsma/66e31f47c1e2f2c14b4652b43f65a8fc
So instead of passing
abortController.signalto node-fetch or a googleapis request, I would passnew AbortSignal(abortController.signal), the main thing here isstatic get name()which returns the proper name even when minimization is fully enabled@1c7 PRs are welcome to fix this issue.
I can not provide reproducible code for now. sorry.
How I encounter this problem?
I am building a Electron.js app that can upload file to Azure Storage. Using
"@azure/storage-blob": "12.1.1"Everything works fine in development, but after I bundle the code for production,This
TypeError: Expected signal to be an instanceof AbortSignalwould popup. After tracking it, I found out it’snode-fetchrasing this error