elementUI按需引入时报错 Cannot find module 'babel-preset-es2015’
解决步骤:
-
首先,安装 babel-plugin-component:
npm install babel-plugin-component -D
-
将 .babelrc(改为
babel.config.js
)修改为:{ "presets": [["es2015", { "modules": false }]], "plugins": [ [ "component", { "libraryName": "element-ui", "styleLibraryName": "theme-chalk" } ] ] }
3.在babel.config.js配置文件把es2015修改成@babel/preset-env:
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset',
["@babel/preset-env", { "modules": false }]
],
plugins: [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}