Rollup failed to resolve import "element-plus/es/components"

vite打包异常,错误信息如下:

复制代码
[vite]: Rollup failed to resolve import "element-plus/es/components" from "node_modules/element-plus/es/index.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
error during build:
Error: [vite]: Rollup failed to resolve import "element-plus/es/components" from "node_modules/element-plus/es/index.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
    at onRollupWarning (/Users/wuqian-mac-mini/Desktop/wuqianWork/nwdGitlab/cxqdjf/yz/change-wechat-web/node_modules/vite/dist/node/chunks/dep-6c23b6f8.js:51247:19)
    at onwarn (/Users/wuqian-mac-mini/Desktop/wuqianWork/nwdGitlab/cxqdjf/yz/change-wechat-web/node_modules/vite/dist/node/chunks/dep-6c23b6f8.js:51032:13)
    at Object.onwarn (/Users/wuqian-mac-mini/Desktop/wuqianWork/nwdGitlab/cxqdjf/yz/change-wechat-web/node_modules/rollup/dist/shared/rollup.js:23216:13)
    at ModuleLoader.handleResolveId (/Users/wuqian-mac-mini/Desktop/wuqianWork/nwdGitlab/cxqdjf/yz/change-wechat-web/node_modules/rollup/dist/shared/rollup.js:22466:26)
    at /Users/wuqian-mac-mini/Desktop/wuqianWork/nwdGitlab/cxqdjf/yz/change-wechat-web/node_modules/rollup/dist/shared/rollup.js:22427:26
复制代码

解决,在 vite.config.js 里添加:

复制代码
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';

export default defineConfig({
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
  resolve: {
    alias: [
      {
        find: '@',
        replacement: path.resolve(__dirname, 'src')
      }
    ]
  },
  build: {
    rollupOptions: {
      external: [
          "element-plus"
      ]
    }
  }
})
复制代码

发布要求字数:凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数凑字数

posted @   Cynthia娆墨旧染  阅读(13085)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示