比如使用mockjs等npm包时,由于打包后的文件是commonjs的,会出现如下错误
Uncaught SyntaxError: The requested module '/@modules/mockjs/src/mock.js' does not provide an export named 'default'
有没有好的解决方法
The best way is to file an issue to mockjs asking for providing ESM builds. For the general support, please track on #720.
You also can used
optimizeDeps inside vite.config.js by bundle it to es module(doc is here https://github.com/vitejs/vite/blob/master/src/node/config.ts#L96)