There will be such an error when installing the on-demand loading of element UI under the official documentation of Vue.
Error:Plugin/Preset files are not allowed to export objects, only functions
In the official document of element
On demand import
With the help of Babel plugin component, we can only introduce the required components to reduce the project volume.
First, install the Babel plugin component:
npm install babel-plugin-component -D
Then, change. Babelrc to:
{
"presets": [["es2015", { "modules": false }]],
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}
At this time, after the installation and configuration are completed according to the official documents, an error will be reported when NPM run serve is started
Error: Cannot find module 'babel-preset-es2015'
This is due to the lack of Babel preset es2015 dependency
Just install the Babel preset es2015 dependency
npm i babel-preset-es2015 --save
This is OK, but sometimes you will still report an error when you start after installation
Error: Plugin/Preset files are not allowed to export objects, only functions.
I changed the preset in the babel.config.js file in the project Not used in the official element UI documentation
Es2015, but change the content of babel.config.js to the following:
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset',
["@babel/preset-env", {
"useBuiltIns": "entry"
}]
],
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}
Then install the dependencies on the command line
npm install --save-dev @babel/preset-env
This solves the error.
Read More:
- Error: Duplicate plugin/preset detected [How to Solve]
- [Solved] Vue Project Start Error: Support for the experimental syntax ‘jsx‘ isn‘t currently enabled
- Module build failed: Error: Couldn’t find preset “es2015” relative to directory
- [Solved] SyntaxError: Cannot use import statement outside a module
- [Solved] Vue3 Import element UI error: Uncaught TypeError: Cannot read properties of underfined…
- [Solved] Syntax Error: Error: Cannot find module ‘@vue/babel-preset-app‘
- [Solved] Front end error: Unknown custom element
- Vuejs composite ElementUI component library error
- [Solved] Vue item error: Regeneratorruntime is not defined
- Vue Import element-plus Error: Failed to resolve import “element-pluslibtheme-chalkindex.css“ from “src
- How to Solve “Vue is not defined” Error
- [Solved] Errors: 1 http://eslint.org/docs/rules/quotes…elementUI Import Error
- [Solved] Install The Latest Version of Jest Error: TypeError: Cannot read property ‘instrument‘ of undefined
- Vue3 + vite install element-plus error [How to Solve]
- Solution to build error in Vue project (error in static/JS)/vendor.xxxxx.js from UglifyJs)
- [Solved] Vuepress Package Error: document is not defined
- Vue Install less Error: While resolving: [email protected]
- Vue3.0 error: Failed to resolve component el-form-item (el element to be unable to be displayed)
- Vue3 Error: [vue/no-multiple-template-root] The template root requires exactly one element
- [Solved] AES encryption in ie11 results in an error (missing ‘)‘