Vue reports an error when babel-preset-es2015 starts a project when adding an on-demand load to the UI library

The

project uses the vue cli3 scaffolding tool to build
as shown in the element official documentation.
npm install babel-plugin-component-D
then add the .babelrc file
{
"presets": [

["es2015", {
  "modules": false
}]

],
"plugins": [

[
  "component",
  {
    "libraryName": "element-ui",
    "styleLibraryName": "theme-chalk"
  }
]

]
}
the startup project found that babel-preset-es2015 was missing, so cnpm install-- save babel-preset-es2015 installed
and then the startup project reported an error
Error: Plugin/Preset files are not allowed to export objects, only functions.. In E:vue3-confignode_modulesbabel-preset-es2015libindex.js
novice Xiaobai asks for online solutions


1. Install the @ babel/preset-env; project directory and run the command line

npm i @babel/preset-env -D

2. Modify the .babelrc file to change es2015 to @ babel/preset-env

{
  "presets": [["@babel/preset-env", { "modules": false }]],
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}

3. Rerun project
in fact, the configuration items of .babelrc can be written to the babel.config.js file, and the .babelrc file is no longer needed after that


it is recommended not to use cnpm to try again, delete all node_module and use npm to try again

Menu