vue added error to element-UI library when starting project when loading on demand babel-preset-es2015 error

The project is built using the vue cli3 scaffolding tool
as shown in the official element documentation.

npm install babel-plugin-component -D

Then add the .babelrc file

{
  "presets": [["es2015", { "modules": false }]],
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}

But can't find .babelrc file in vue cli3

Find through the network can be configured in babel.config.js

module.exports = {
  "presets": [["es2015", { "modules": false }]],
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}

Run error

Error: Cannot find module 'babel-preset-es2015' from

Solution:

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

npm i @babel/preset-env -D

2. Modify the babel.config.js file and change es2015 to @ babel / preset-env

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

 

Guess you like

Origin www.cnblogs.com/wukaiBK/p/12757945.html