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]
- Module build failed: Error: Couldn’t find preset “es2015” relative to directory
- [Weex]Error in creating project NPM: unable to load file D:\program files\nodejs\node_ global\ weex.ps1 Because scripts are not allowed to run on this system.
- [Solved] react-router-dom Error: index.js:1 Warning: Functions are not valid as a React child.
- [Solved] Syntax Error: Error: Cannot find module ‘@vue/babel-preset-app‘
- [Solved] Vue Project Start Error: Support for the experimental syntax ‘jsx‘ isn‘t currently enabled
- [Solved] Uncaught SyntaxError: The requested module does not provide an export named
- How to Fix “HTTP 405 method not allowed” Error
- [Solved] Error: #error More than 1 blank line not allowed no-multiple-empty-lines
- [Solved] Failed to load plugin ‘vue‘ declared in ‘.eslintrc.js‘: createRequire is not a function
- [Solved] Vue unit test syntax error: unexpected token ‘export‘
- [Solved] Cnpm installation -g@ view/cli Error: error: eperm: operation not allowed…
- [Solved] Vue item error: Regeneratorruntime is not defined
- vue3 import Error: has no default export [How to Solve]
- [Solved] node.js Upload Files Error: Multipart: boundary not found multer
- [Solved] error when starting dev server:Error: The following dependencies are imported but could not be reso
- JS async await Error: Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
- [Solved] arco design vite-plugin-style-import Load menu-item error: Internal server error…
- [Solved] vueCli 4.x Upgrade to 5.x Error: Progress Plugin Invalid Options
- [Solved] SyntaxError: Cannot use import statement outside a module