question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to decode base64 []: atob is not defined

See original GitHub issue

Since https://github.com/upstash/upstash-redis/pull/198 I’m getting Unable to decode base64 []: atob is not defined warnings while running the library inside a Vercel API route.

I’m using automaticDeserialization, the feature might not be able compatible with it ?

Downgrading to version 1.13.1 does solve the issue, so it’s clearly that commit that caused the issue.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12

github_iconTop GitHub Comments

3reactions
chronarkcommented, Oct 17, 2022

👍 I’ll leave this open until I merge the fix thanks for the report

1reaction
BurakGurcommented, Oct 28, 2022
if (typeof atob === 'undefined') {
  global.atob = function (b64: string) {
    return Buffer.from(b64, 'base64').toString('utf-8');
  };
}

I use this one for react native:

if (!global.atob) {
  global.atob = function atob(input) {
    var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
    var output = '';
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;
    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
    do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));
      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;
      output = output + String.fromCharCode(chr1);
      if (enc3 !== 64) {
        output = output + String.fromCharCode(chr2);
      }
      if (enc4 !== 64) {
        output = output + String.fromCharCode(chr3);
      }
    } while (i < input.length);
    return output;
  };
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js throws "btoa is not defined" error - Stack Overflow
The 'btoa-atob' module does not export a programmatic interface, it only provides command line utilities. If you need to convert to Base64 ......
Read more >
atob is not defined, When using with nodeJS backend · Issue #4
In Windows it fail here slice.charCodeAt(i); with error: Uncaught TypeError: slice.charCodeAt is not a function at b64toBlob (misc.js:210:1).
Read more >
Base64 Encode and Decode in Node.js - eloquent code
Using Node on the server side, we find that we cannot use the JavaScript functions atob and btoa. They are not defined; we...
Read more >
atob() - Web APIs - MDN Web Docs
The atob() function decodes a string of data which has been encoded using Base64 encoding. You can use the btoa() method to encode...
Read more >
js-base64 - npm
// or if you prefer no Base64 namespace import { encode, decode } from 'js-base64';. or even remotely. <script type="module"> // ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found