Laravel+Vue项目构建后报Super expression must either be null or a function错误
问题
开发环境执行npm run dev时一切正常,但构建项目后出现以下错误:
Super expression must either be null or a function, not undefined.
移除BlotFormatter模块后项目可正常运行。
技术栈:laravel + vue + inertia + vite + VueQuill
相关代码示例:
<template> <div> <QuillEditor theme="snow" :modules="modules"/> </div> </template> <script> import { QuillEditor } from '@vueup/vue-quill' import BlotFormatter from 'quill-blot-formatter' import '@vueup/vue-quill/dist/vue-quill.snow.css'; export default { components: { QuillEditor }, setup: () => { const modules = { name: 'blotFormatter', module: BlotFormatter, options: {/* options */} } return { modules } }, } </script>
解决方案
这个错误是因为BlotFormatter模块的注册方式不符合VueQuill的要求,且未正确绑定到Quill实例中,导致生产构建时模块无法被正确识别。按以下步骤修改:
修正模块配置结构
VueQuill的modules配置需以模块名为键、配置内容为值,而非原代码中的结构。同时要从@vueup/vue-quill导入Quill来完成模块注册。正确注册BlotFormatter到Quill
导入模块后,通过Quill.register将其注册为Quill的官方模块。
修改后的完整代码:
<template> <div> <QuillEditor theme="snow" :modules="modules"/> </div> </template> <script> import { QuillEditor, Quill } from '@vueup/vue-quill' import BlotFormatter from 'quill-blot-formatter' import '@vueup/vue-quill/dist/vue-quill.snow.css'; // 注册BlotFormatter到Quill Quill.register('modules/blotFormatter', BlotFormatter) export default { components: { QuillEditor }, setup: () => { const modules = { blotFormatter: { // 在这里添加你的模块配置选项 } } return { modules } }, } </script>
- 可选:优化Vite构建配置
如果修改代码后仍有问题,可在vite.config.js中添加依赖优化,避免生产构建时模块被错误摇树:
export default { optimizeDeps: { include: ['quill-blot-formatter'] } }
内容的提问来源于stack exchange,提问作者Martin P
相关产品推荐
相关产品推荐

