react-native TypeError: adapter is not a function?

运行react-native android的时候得到这样的错误

Possible Unhandled Promise Rejection (id: 0): TypeError: adapter is not a function. (In 'adapter(config)', 'adapter' is undefined) dispatchRequest@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:126225:19 tryCallOne@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:27056:16 http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:27157:27 _callTimer@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:30596:17 _callImmediatesPass@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:30635:17 callImmediates@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:30852:33 __callImmediates@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2736:35 http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2522:34 __guard@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2719:15 flushedQueue@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2521:21 flushedQueue@[native code] callFunctionReturnFlushedQueue@[native code]

运行环境:
react-native^63
axios

axios config:

import axios from 'axios';
import {getAccessToken} from './util'

const service = axios.create({
    baseURL: '/',
    timeout: 6000
})
var token;


service.interceptors.request.use(config => {
    token = getAccessToken()
    if (config.headers['Content-Type']) {
        console.log(config.headers['Content-Type'])
    } else {
        config.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
    }
    config.headers['Authorization'] = `Bearer ${token}`
    return config
}, error => {
    return Promise.reject(error)
})

service.interceptors.response.use(response => {
    return response.data
}, error => {
    return Promise.reject(error)
})

export {service as axios}

登录请求:

const {code, message, data} = await login({phone, password})
setLoading(false)
if (code === 1) {
  saveAccessToken(data.access_token)
  ToastAndroid.showWithGravity(
    message,
    ToastAndroid.SHORT,
    ToastAndroid.CENTER
  )
  getInfo(data.access_token)
  navigation.navigate('Home');
} else {
  setErrortext(message)
  return
}

storage:

const saveAccessToken = async (accessToken) => {
      try {
          await AsyncStorage.setItem('access_token', accessToken)
      } catch (error) {
          return error
      }
  }

error-img

开启debugger后可以登录运行正常, 关掉debugger后救我无法登录了提示:
Possible Unhandled Promise Rejection (id: 0): TypeError: adapter is not a function. (In 'adapter(config)', 'adapter' is undefined)? ......
也不知道哪里的错误,有懂的求指点一下,谢谢

阅读 4.5k
1 个回答

已找到原因, 使用rn-fetch-blob 发送请求的时候出的错, 之前控制台一直报这个包的错,我觉得应该不是这个的原因, 把这个包卸载掉好了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题