Failed to resolve import “element-plus/es/el-sub-menu” from "src\components\
Vue3+vite automatically introduces element plus on demand and reports errors
First, you need to install the two plug-ins unplugin-vue-components and unplugin-auto-import,
npm install -D unplugin-vue-components unplugin-auto-import
and then insert the code in the on-demand automatic import into your vite configuration file
vite.config.js
import { defineConfig } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig({
// ...
plugins: [
// ...
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),
],
})
Copy the code, follow the steps on the official website to add and import the element component, and an error occurs.
First, check whether the import order in the configuration file is appropriate. If the order is not appropriate, an
error will also be reported. If the order is the same as the above picture, it may be because of the plug-in version. If the order
is as follows The plug-in installed in this way
npm i element-plus
can run normally by changing the version of elementUI plus to the following
npm i [email protected]