【问题标题】:Axios is throwing an error abortSignal during the build?Axios 在构建过程中抛出错误 abortSignal?
【发布时间】:2022-10-30 09:08:04
【问题描述】:

我正在尝试在 nodejs typescript 项目中使用 axios,并且在构建过程中它抛出错误 abortSignal 对此问题的任何修复感谢帮助

索引.ts

export async function getAccessToken(apiConfig: any) {

        const req = {
            grant_type: apiConfig.authOptions.body.grant_type,
            client_id: apiConfig.authOptions.credentials.clientId,
            client_secret: apiConfig.authOptions.credentials.clientSecret,
            scope: apiConfig.authOptions.body.scope
        };
        const headers = {
            "Content-Type": "application/x-www-form-urlencoded",
            "appName": "Blink"
        };
        try {
            const resp: AxiosResponse = await axios.post('https://test.com//auth/oauth2/token',
            req, { headers });
            console.log(resp.data);
        } catch (err) {
            // Handle Error Here
            console.error(err);
        }
    }

错误

node_modules/axios/index.d.ts(93,12): error TS2304: Cannot find name 'AbortSignal'.

包.json

"axios": "^0.24.0",

【问题讨论】:

标签: javascript node.js typescript axios


【解决方案1】:

尝试在 axios 参数中提供 abortController 信号: 常量中止控制器=新中止控制器; const resp: AxiosResponse = await axios.post('https://test.com//auth/oauth2/token', 请求,{标头},信号:abortController.signal);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    • 1970-01-01
    • 2021-06-28
    相关资源
    最近更新 更多