未捕获(承诺中)错误:错误:适配器“http”在构建中不可用

问题描述 投票:0回答:3

我正在尝试在 React chrome 扩展模块中使用 axios,但我遇到了这个问题。

未捕获(承诺中)错误:错误:适配器“http”在构建中不可用

// background.ts

import axios from "axios"
...
axios.get<SerInyResponse>("https://realtor.p.rapidapi.com/locations/v2/auto-complete")
            .then(response => {
                this.Storage.setLocalStorage(response.data).then( (re) => {
                    resolve(response.data.Listeners)
                })
                
            })
            .catch( err => {
                reject(new Error(err))
            })

有人可以帮助我吗?

reactjs google-chrome-extension axios chrome-extension-manifest-v3
3个回答
4
投票

用 Fetch 写入

const res = await fetch(url, { method: "GET", credentials: "include", headers: { Cookie: token }, });


4
投票

Service Worker 仅支持 fetch


0
投票

因为中间件仅支持 fetch,所以基于

http
模块的 axios 在边缘运行时不支持。目前唯一的办法就是使用fetch,或者尝试
xior
,基于fetch,类似axios API,插件支持,非常精简的大小,支持bun/deno/vite/react/expo/react-native等:

https://github.com/suhaotian/xior

© www.soinside.com 2019 - 2024. All rights reserved.