最近在寫一個(gè)node項(xiàng)目時(shí),webpack打包之后運(yùn)行打包的js文件報(bào)錯(cuò):
?[AxiosError]: There is no suitable adapter to dispatch the request since :
- adapter xhr is not supported by the environment
- adapter http is not available in the build
? ? at we (C:\Users\lzz\Documents\網(wǎng)盤腳本\dist\bundle.js:2:32230)
? ? at Ce.Se (C:\Users\lzz\Documents\網(wǎng)盤腳本\dist\bundle.js:2:32728)
? ? at async t.getInfo (C:\Users\lzz\Documents\網(wǎng)盤腳本\dist\bundle.js:2:6321)
? ? at async C:\Users\lzz\Documents\網(wǎng)盤腳本\dist\bundle.js:2:40339 {
? code: 'ERR_NOT_SUPPORT'
在網(wǎng)上找了半天發(fā)現(xiàn)網(wǎng)上沒有一篇關(guān)于這個(gè)問題的解決方案,后來查閱axios官方文檔,找到這個(gè)問題的根源,官方給出適用于CommonJS的axios包:文章來源:http://www.zghlxwxcb.cn/news/detail-768199.html
為了直接使用?require
?導(dǎo)入預(yù)構(gòu)建的 CommonJS 模塊(如果您的模塊打包器無法自動(dòng)解析它們),我們提供了以下預(yù)構(gòu)建模塊:文章來源地址http://www.zghlxwxcb.cn/news/detail-768199.html
const axios = require('axios/dist/browser/axios.cjs'); // browser
const axios = require('axios/dist/node/axios.cjs'); // node
到了這里,關(guān)于[AxiosError]: There is no suitable adapter to dispatch the request since :- adapter xhr is not suppo的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!