webpack 编译 element-plus 报错

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值