node12使用axios报错:
Module not found: Error: Package path ./lib/helpers/buildURL is not exported from package
import buildURL from "axios/lib/helpers/buildURL";
import { merge } from "axios/lib/utils";
一、原因:对于 import axios from ‘./lib/axios.js’ axios/lib/helpers/buildURL这样 esm 方式的导入,node12版本无法识别,Node 13.2 开始才原生支持 esm。
二、解决方法:
- 升级node版本
- 在vue.config.js中添加alias
const { defineConfig } = require("@vue/cli-service");
const path = require("path");
module.exports = defineConfig({
configureWebpack: {
resolve: {
alias: {
"axios/lib": path.resolve(__dirname, "./node_modules/axios/lib"),
},
},
},
});
修改之后报错:
axios_lib_utils__WEBPACK_IMPORTED_MODULE_2__.merge) is not a function
修改为:
//import { merge } from "axios/lib/utils";
import utils from "axios/lib/utils";
const merge = utils.merge;
问题解决
标签:axios,lib,utils,buildURL,helpers,import,报错,path From: https://blog.csdn.net/weixin_40437521/article/details/141162560