axios: Can't find variable: btoa
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
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 14
- Comments: 21
Commits related to this issue
- fix issue #2235 — committed to Alanscut/axios by Alanscut 5 years ago
- Install axios 0.18.0 The lastest version for now contains `Can't find variable: btoa` https://github.com/axios/axios/issues/2235 — committed to fikrikarim/gitfeed by fikrikarim 4 years ago
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)
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.
put “axios”: “0.18.0” in project dependencies that’s worked for me
@Alanscut @SyneticDevOps According to #1689, it is not a bug, but an intentional change. If you want an out-of-box usage, you have to lock axios to ~0.18.0. Or you should add global
btoa
polyfill by yourself.@chinesedfan What is your team’s intention to remove
btoa
from Axios?Well, seems like the btoa polyfill has been removed, which causes this issue: https://github.com/axios/axios/compare/v0.18.0...v0.19.0
Also removed in v0.18.1 https://github.com/axios/axios/compare/v0.18.0...v0.18.1
I’m experiencing this same bug in axios 0.19.0. Downgrading to 0.18.0 seems to help for now.