Module not found: Error: Package path ./lib/core/settle is not exported from package D:\xxx\xxx\n...

使用vue-cli創(chuàng)建的uniapp項(xiàng)目,在封裝axios時(shí),寫了如下代碼:

axiosInter.defaults.adapter = function (config) {
    return new Promise((resolve, reject) => {
        // console.log(config)
        var settle = require("axios/lib/core/settle");
        var buildURL = require("axios/lib/helpers/buildURL");
        uni.request({
            method: config.method.toUpperCase(),
            url: buildURL(config.url, config.params, config.paramsSerializer),
            header: config.headers,
            data: config.data,
            dataType: config.dataType,
            responseType: config.responseType,
            sslVerify: config.sslVerify,
            complete: function complete(response) {
                response = {
                    data: response.data,
                    status: response.statusCode,
                    errMsg: response.errMsg,
                    header: response.header,
                    config: config,
                };

                settle(resolve, reject, response);
            },
        });
    });
};

require('axios/lib/core/settle')時(shí)報(bào)錯(cuò)Module not found: Error: Package path ./lib/core/settle is not exported from package D:\cloud2\uniapp\node_modules\axios,
require("axios/lib/helpers/buildURL")時(shí)也同樣報(bào)錯(cuò)

解決辦法:package.json中查看axios版本為1.3.4,為當(dāng)前最新版本,猜測是因?yàn)榘姹咎邔?dǎo)致,于是重新下載舊版本0.26.1,重新啟動項(xiàng)目無報(bào)錯(cuò)。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容