新建vue3项目的过程中,使用webpack打包,编译element-plus时报错
ERROR in ./node_modules/element-plus/es/components/time-picker/src/time-picker.mjs 3:0-63
Module not found: Error: Can't resolve 'dayjs/plugin/customParseFormat' in '/Users/zjlab/Documents/workSpace/zj-wasc-jobManage-frontEnd/node_modules/element-plus/es/components/time-picker/src'
Did you mean 'customParseFormat.js'?
BREAKING CHANGE: The request 'dayjs/plugin/customParseFormat' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
@ ./node_modules/element-plus/es/components/time-picker/index.mjs 1:0-47 8:20-30
@ ./node_modules/element-plus/es/index.mjs 134:0-66 134:0-66
@ ./src/main.js 3:0-38 8:8-19
问题的关键在这儿:
找到相关文件:time-picker.mjs
到这儿问题就明显了,webpack没有配置.mjs后缀文件的编译方式,
所以我们加了:

resolve: {
fullySpecified: false,
},这个配置是让webpack不严格按照后缀去引入依赖,可以自己补充文件后缀

webpack的配置也需要加extensions:


本文介绍了在新建Vue3项目时,遇到element-plus编译错误,主要涉及如何在webpack配置中添加对.mjs文件的支持,以解决模块解析'customParseFormat'未找到的问题。通过设置resolve.fullySpecified和extensions,确保webpack能正确编译项目。
2621

被折叠的 条评论
为什么被折叠?



