一勺大白
居家办公摸鱼程序猿...主修 PHP+Vue 的全栈!
关于 json-editor-vue3 的一次排错记录
关于 json-editor-vue3 的一次排错记录
发布时间:2024年10月27日 浏览量:5285

 

最近在把 之前的开发框架 从 Naive UI 转换成 Element plus。

其中有功能要用到 json-editor-vue3写到这块功能的时候。发现只是在组件引入了插件。

import JsonEditorVue from 'json-editor-vue3'

会导致,页面没办法正常打开,路由跳转也失效了。没办法正常跳转。

控制台报错

SyntaxError: The requested module '/rmrf/node_modules/.pnpm/registry.npmmirror.com+jsoneditor@9.10.2/node_modules/jsoneditor/dist/jsoneditor.min.js?v=b9635e1c' does not provide an export named 'default'

看到这个问题,第一反应是引入旧版文件的问题。

但是在之前的项目就没有这种报错。对比新老项目的vite.config.js 最后排查到问题。因为新项目少引入了。

import {viteCommonjs} from '@originjs/vite-plugin-commonjs'

Vite 只支持ES规范。 不支持CommonJS。所以在项目中要使用 module import

添加 @originjs/vite-plugin-commonjs 可以让 Vite 兼容 CommonJS。