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.

Can't find variable: btoa

See original GitHub issue

Describe the bug Using Basic Auth with axios in an expo app causes this error. It was working before upgrading both axios and expo, not sure what is causing the issue but seems btoa function is not available in expo envirorment.

To Reproduce Make a get request with auth headers from an expo app

let axiosInstance = axios.create({
  baseURL: 'http://example.com',
  auth: {
    username: 'user',
    password: 'password'
  }
});
axiosIstance.get('/path/to');

Environment:

  • Axios Version 0.18.0
  • expo 32.0.0
  • react 16.5

Additional context/Screenshots Schermata 2019-06-16 alle 21 52 09

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:14
  • Comments:21

github_iconTop GitHub Comments

20reactions
Samyang061195commented, Jul 17, 2019

Hi, I’m new in GitHub, however let me try to help. Solved the current issue (Axios Removed btoa variable Polyfill) with these steps: (Used in React-Native Project)

  1. Install base-64 npm package, npmjs.com/package/base-64 ,
  2. You can set atob and btoa as global variables on React Native. Then, you won’t need to import them on each file you need it. Add the following at beginning of your index.js, so that it can be loaded before another file uses atob and btoa:

import {decode, encode} from ‘base-64’

if (!global.btoa) { global.btoa = encode; }

if (!global.atob) { global.atob = decode; }

Source : https://stackoverflow.com/questions/42829838/react-native-atob-btoa-not-working-without-remote-js-debugging.

Hopefully Helps.

Thanks.

3reactions
aqweidercommented, Sep 19, 2019

put “axios”: “0.18.0” in project dependencies that’s worked for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native atob() / btoa() not working without remote JS ...
You can set atob and btoa as global variables on React Native. Then, you won't need to import them on each file you...
Read more >
Can't find variable: btoa - Hybrid - CometChat Forum
Hi My app is using expo 35.0.0 with react native sdk-35.0.0 I can initialize cometchat and i can create the user When i...
Read more >
[Resolved] Can't Find Variable btoa in Mobile Preview
Context: • I have a custom function that uses "btoa" to encode base64 certain fields (used in 2 pages) • The function works...
Read more >
react native base64, referenceerror: can't find variable
Solved the current issue (Axios Removed btoa variable Polyfill) with these steps: (Used in React-Native Project) Install base-64 npm package, npmjs.com/package/ ...
Read more >
Developers - Can't find variable: btoa - - Bountysource
Can't find variable : btoa ... I tried to install btoa and atob via npm but it is not working. See More. View...
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