vite 配置 quill-image-resize-module 报错 Cannot read properties of undefined (reading 'imports')
时间: 2023-07-01 16:28:21 浏览: 99
这个问题通常是因为 Quill 和 Quill Image Resize Module 版本不兼容导致的,需要将 Quill Image Resize Module 升级到最新版本。你可以尝试以下步骤:
1. 确认 Quill 和 Quill Image Resize Module 的版本是否匹配。可以通过 Quill Image Resize Module 的官方文档确认他们的版本兼容性。
2. 将 Quill Image Resize Module 升级到最新版本。可以通过以下命令升级:
```
npm install quill-image-resize-module@latest
```
当然,你也可以在 `package.json` 文件中将 `quill-image-resize-module` 的版本指定为最新版本:
```
"quill-image-resize-module": "^3.0.0"
```
然后执行 `npm install` 命令进行更新。
3. 在 Vite 中使用 `rollup-plugin-node-resolve` 插件解决依赖问题。首先安装该插件:
```
npm install --save-dev rollup-plugin-node-resolve
```
然后在 `vite.config.js` 文件中添加以下配置:
```javascript
import { defineConfig } from 'vite';
import { nodeResolve } from '@rollup/plugin-node-resolve';
export default defineConfig({
build: {
rollupOptions: {
plugins: [
nodeResolve({
mainFields: ['module', 'main', 'jsnext:main'],
browser: true,
extensions: ['.js', '.json'],
preferBuiltins: false,
}),
],
},
},
});
```
这个配置会告诉 Rollup 打包时先去解析 Quill 和 Quill Image Resize Module 的依赖关系,从而避免出现找不到依赖的问题。
希望这些解决方案能够帮助你解决问题。