diff --git a/src/_shims/formdata.js b/src/_shims/formdata.js index a3debe98..8cbe41c4 100644 --- a/src/_shims/formdata.js +++ b/src/_shims/formdata.js @@ -3,7 +3,15 @@ */ exports.FormData = FormData; -exports.File = File; exports.Blob = Blob; +exports.File = + typeof File !== 'undefined' ? File : ( + // Bun doesn't implement File yet, so just make a shim that throws a helpful error message + class File extends Blob { + constructor() { + throw new Error(`file uploads aren't supported in this environment yet as 'File' is not defined`); + } + } + ); exports.isPolyfilled = false; diff --git a/src/_shims/formdata.mjs b/src/_shims/formdata.mjs index 2871d130..3ee740bd 100644 --- a/src/_shims/formdata.mjs +++ b/src/_shims/formdata.mjs @@ -3,9 +3,18 @@ */ const _FormData = FormData; -const _File = File; const _Blob = Blob; +const _File = + typeof File !== 'undefined' ? File : ( + // Bun doesn't implement File yet, so just make a shim that throws a helpful error message + class File extends Blob { + constructor() { + throw new Error(`file uploads aren't supported in this environment yet as 'File' is not defined`); + } + } + ); + export { _FormData as FormData, _File as File, _Blob as Blob }; export const isPolyfilled = false;