Vite 动态引入问题(写法上如何兼容Vite2 + Vue3 和 WebPack3 + Vue2)?

445 阅读1分钟

我需要在 Vite2 + Vue3 中 和 WebPack3 + Vue2 中兼容使用Element。

其中需要引用到ElDialog,在 Vite + Vue3 环境下动态引用 element-ui 时,要如何动态引入才能运行时不报错?

目前使用了require,但是Vite 用require会warnning:

The following dependencies are imported but could not be resolved: element-ui (imported by D:/……/index.js) Are they installed?

会 main.js 加载进程一直pending,单独注释掉这一段代码重新运行后项目又能跑起来,删除node_modules 整个包,npm cache clean --force后,再npm install,又能复现。

求助。