From 24cd9188ea0e76ae33ced4e621b1fb8b5cefda5c Mon Sep 17 00:00:00 2001 From: Josh Ellis Date: Wed, 3 Feb 2021 18:52:41 +0000 Subject: [PATCH] fix: esm-modules break because Buffer is not available --- src/helpers/base64.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/helpers/base64.ts b/src/helpers/base64.ts index c531ab55b..9807c43d1 100644 --- a/src/helpers/base64.ts +++ b/src/helpers/base64.ts @@ -12,7 +12,8 @@ function fixBinary(bin) { } // polyfill for SSR as atob is not available - https://gist.github.com/jmshal/b14199f7402c8f3a4568733d8bed0f25 -const atobPolyfill = (a: string) => Buffer.from(a, 'base64').toString('binary') +const atobPolyfill = (a: string) => + typeof window === undefined ? Buffer.from(a, 'base64').toString('binary') : atob(a) export const createImageUrl = (blob: string, type: string) => URL.createObjectURL(new Blob([fixBinary(atobPolyfill(blob))], { type }))