You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is there a way to remove "TypeError: Expected signal to be an instanceof AbortSignal"? #784
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 have class.name to get the class name, I am not sure what's the equivalent in JS
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 AbortSignal would popup.
After tracking it, I found out it's node-fetch rasing this error
I hope this problem can be fixed,
Because I want to turn on code minify for my electron.js main process code.
For now, I have to turn it off
(File size 898kb -> 2.3mb)
@Richienb
Even though just changing this one line,
I have to run all the test and make sure not to break other things,
and understand how other pieces works
it's still quite complicated,
Would you mind helping me fix this?
Or let other core members who are familiar with these codes to fix it?
This is src/background.js file after running npm run electron:build
For comparison (This doesn't work)
node-fetch would raise error
Reacted by Matthew Rayermann, Ruurd Bijlsma, Tim Etchells, avocadowastaken, Chris, Peter JZ, Andrei, Gintaras Volkvičius, Nikita Dmitriev and idwessough
So instead of passing abortController.signal to node-fetch or a googleapis request, I would pass new AbortSignal(abortController.signal), the main thing here is static get name() which returns the proper name even when minimization is fully enabled
RuurdBijlsma sugarcode looks nice, but, can not be use in a typescript project:
The Typescript transpiler refused to overwrite the name getter with the Error:
Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'AbortSignal'.ts(2699)
Setting keep_classnames: true in the TerserPlugin works, but this change is applied to all classnames, I do not see any option in the TerserPlugin to provide a set of classname to keep untouched.
// keep_classnames is required to workaround node-fetch Expected signal to be an instanceof AbortSignal
config.optimization = {
minimizer: [
new TerserPlugin({
cache:true,
parallel:true,
sourceMap:true, // Must be set to true if using source-maps in production
terserOptions: {
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
mangle:false,
sourceMap:true,
// compress: false,
keep_classnames:/AbortSignal/,
keep_fnames:/AbortSignal/,
output: {
beautify:true,
indent_level:1
}
}
}),
],
};
Reacted by andersrydman, Rick Chow, Carl Elgestad Stjernfeldt, Yannis Kommana, Ivo Heidelbach, Zach Goldberg, benzsuankularb, Raúl Juárez, Andrew Welch, Troy Poulter and 13 more
Reacted by Carl Elgestad Stjernfeldt, benzsuankularb, Andrew Ribeiro, Eric L Carraway, Minh-Phuc Tran, Nadhir, marek-mularczyk-vaimo and Sejir BEN ALI
Reacted by Carl Elgestad Stjernfeldt, Henning Hoefer, Zach Goldberg, JC Estibariz, Raúl Juárez, Andrew Ribeiro, Eric L Carraway, Minh-Phuc Tran, Nadhir, marek-mularczyk-vaimo and 2 more
I came up to this problem (using Esbuild) and fixed that by making the package that uses node-fetch (in my case @sanity/client) as external resource or in other words, excluding the package from the bundling itself:
// build.js// ...constbaseConfig={external: ['@sanity/client',/* ... other external dependencies ... */]}
I tried the suggestion from @domgenv to set keepNames to true but unfortunately it didn't work.
A bit more information, in case anyone is curious: As mentioned in #784 (comment), current versions of node-fetch use Symbol.toStringTag, so they should work just fine, even after minification. node-fetch 2.x (the most recent pre-ESM version, and the version used by, e.g., @azure/storage-blob 12.12.0) still checks against name, so it's affected by this (and can be fixed by adding one of the keep-names options).
For reference, when using terser with @swc/core this is the minimal config to fix this issue in your webpack config. It does not appear to support regexes for keep_classnames nor keep_fnames
optimization: {minimizer: [newTerserPlugin({minify: TerserPlugin.swcMinify,terserOptions: {mangle: {// older versions of node-fetch requires AbortSignal to be untouched.// https://github.com/node-fetch/node-fetch/issues/784reserved: ['AbortSignal'],},},}),]},
FYI 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:
Reacted by Davy Landman, Kheang Hok Chin, saykumar, Philipp, Mark D'Arensbourg, Titouan CREACH, BastienGenin, fkoemep, Jacob Hummer, ntorrey and 1 more
Reacted by Christopher Peisert, Xu Han, fkoemep, ntorrey and cjenkscybercom
Activity
1c7 commentedon Apr 23, 2020
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's
node-fetchrasing this error1c7 commentedon Apr 23, 2020
I hope this problem can be fixed,
Because I want to turn on code minify for my electron.js main process code.
For now, I have to turn it off
(File size 898kb -> 2.3mb)
Richienb commentedon Apr 23, 2020
Using
Symbol.toStringTagwas supposed to prevent this specific problem.1c7 commentedon Apr 23, 2020
@Richienb Thank you for helping, so should I send a PR or? What's the next step?
Richienb commentedon Apr 23, 2020
@1c7 PRs are welcome to fix this issue.
1c7 commentedon Apr 23, 2020
@Richienb
Even though just changing this one line,
I have to run all the test and make sure not to break other things,
and understand how other pieces works
it's still quite complicated,
Would you mind helping me fix this?
Or let other core members who are familiar with these codes to fix it?
Really appreciate that, Thanks!
Thanks for building node-fetch, helpful lib!
1c7 commentedon Apr 23, 2020
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 errorRuurdBijlsma commentedon Dec 20, 2020
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 enabledUrielCh commentedon Jan 4, 2021
RuurdBijlsma sugarcode looks nice, but, can not be use in a typescript project:
The Typescript transpiler refused to overwrite the
namegetter with the Error:Setting
keep_classnames: truein the TerserPlugin works, but this change is applied to all classnames, I do not see any option in the TerserPlugin to provide a set of classname to keep untouched.#1001 fix the issue, but only on NodeJS v15+
Fix AbortSignal from crosis disagreeing with node-fetch
turansky commentedon Feb 25, 2021
WA, which save single name
AbortSignalSource
Include original error in error message; downgrade to airtable 0.8.1;…
domgenv commentedon Jan 17, 2022
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
raulfdm commentedon Jan 22, 2022
I came up to this problem (using Esbuild) and fixed that by making the package that uses
node-fetch(in my case@sanity/client) as external resource or in other words, excluding the package from the bundling itself:I tried the suggestion from @domgenv to set
keepNamesto true but unfortunately it didn't work.Gbr22 commentedon Jan 29, 2022
#784 (comment) How could I achieve this with nuxtjs?
joshkel commentedon Oct 20, 2022
A bit more information, in case anyone is curious: As mentioned in #784 (comment), current versions of node-fetch use
Symbol.toStringTag, so they should work just fine, even after minification. node-fetch 2.x (the most recent pre-ESM version, and the version used by, e.g.,@azure/storage-blob12.12.0) still checks againstname, so it's affected by this (and can be fixed by adding one of the keep-names options).yantze commentedon Oct 24, 2022
Node.js 16.x internal AbortController can use in node-fetch 2.x.
Disable minify
vlinder commentedon Dec 21, 2023
For reference, when using terser with
@swc/corethis is the minimal config to fix this issue in your webpack config. It does not appear to support regexes forkeep_classnamesnorkeep_fnames[gatsby-plugin-vercel-builder] use --keep-names esbuild flag (#11117)
Squashed commit of the following:
dimaboychev commentedon Feb 22, 2024
FYI 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:
shinebayar-g commentedon Apr 16, 2024
If anyone is using https://github.com/actions/toolkit/tree/main/packages/artifact v2 with esbuild and facing this issue, using
--keep-names(https://esbuild.github.io/api/#keep-names) flag seems to be fixing the issue. Thanks to the above linked issue.