新建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:

 

Logo

前往低代码交流专区

更多推荐