apisauce on Expo Web caught TypeError: axios.create is not a function

181 Views Asked by At

I'm trying to create a Expo web project to get some data from a webserver using apisauce

When i build for Android it works fine, but when i try to run on web its givin me this error

caught TypeError: axios.create is not a function
    at create (apisauce.js:1:1)
    at ./src/api/config/index.ts (index.ts:9:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)
    at ./src/api/controllers/ClienteController.tsx (index.ts:24:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)
    at ./src/navigation/screens/LiberacaoScreen.tsx (InscricaoScreen.tsx:171:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:62:1)

Here is my config.ts

import { create } from "apisauce";
import axios from "axios";
import Constants from "expo-constants";

export const apiSauce = create({
    baseURL: Constants.expoConfig?.extra?.apiURL,
    headers: {
        // "Access-Control-Allow-Headers": "Content-Type",
        // "Access-Control-Allow-Methods": "OPTIONS,POST,GET",
        // "Access-Control-Allow-Origin": "*",
        // "Content-Type": "application/json",
        // "Http-Equiv": "Content-Security-Policy",
        "Accept": "*/*",
        
    },
    httpsAgent: {
        rejectUnauthorized: false
    }
});

My packages.json

"dependencies": {
    "@expo/webpack-config": "^18.0.1",
    "@react-navigation/drawer": "^6.6.3",
    "@react-navigation/native": "^6.1.7",
    "apisauce": "^3.0.1",
    "axios": "^1.4.0",
    "expo": "~48.0.18",
    "expo-status-bar": "~1.4.4",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.71.8",
    "react-native-gesture-handler": "~2.9.0",
    "react-native-mask-text": "^0.14.1",
    "react-native-modal-datetime-picker": "^15.0.1",
    "react-native-paper": "^5.9.0",
    "react-native-reanimated": "~2.14.4",
    "react-native-safe-area-context": "4.5.0",
    "react-native-screens": "~3.20.0",
    "react-native-text-input-mask": "^3.2.0",
    "react-native-web": "~0.18.10"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@types/react": "~18.0.14",
    "typescript": "^4.9.4"
  },

I tried to import axios but without success

0

There are 0 best solutions below