From e6d3a5c385e98d2ae0e9d352b0a96d4205179dfc Mon Sep 17 00:00:00 2001 From: Josh <37798644+joshuaellis@users.noreply.github.com> Date: Wed, 3 Feb 2021 18:55:12 +0000 Subject: [PATCH] fix: esm-modules break because Buffer is not available (#287) --- 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 }))