dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

fix: dayjs未暴露module入口,不支持在工具库中使用rollup打包

Open cumt-robin opened this issue 3 years ago • 1 comments

使用方式:

import type { OpUnitType, QUnitType, ManipulateType } from "dayjs"
import dayjs from "dayjs";

使用 rollup 打包,报错信息如下:

[10:49:29] 'buildBundle' errored after 12 s
[10:49:29] Error: 'default' is not exported by node_modules/dayjs/dayjs.min.js, imported by packages/utils/src/date-utils.ts

dayjs 是支持 esm 的, image

经分析,推测原因是因为 dayjs 的 package.json 中没有指定 module 字段,导致 rollup 默认从 main 入口访问到了 dayjs.min.js。 image

而 rollup 是基于 esm 打包的,所以会有一点问题。 我尝试加了一个 module 入口,可以支持 rollup 打包。 image

建议增加一个module入口,直接指向 esm/index.js。提升 esm 支持的友好度。

cumt-robin avatar Jul 26 '22 03:07 cumt-robin

@iamkun 您好,我们倾向于直接使用 import dayjs from "dayjs" 如果直接指定 import dayjs from "dayjs/esm" 对打包工具库来说不是特别友好,我们希望同时能输出 esm 和 cjs, umd 等格式。 所以有 module 字段可能要好一点。

cumt-robin avatar Sep 15 '22 09:09 cumt-robin

Try latest v2 alpha.

sxzz avatar Sep 30 '22 13:09 sxzz

您的邮件我已收到!  我会在第一时间内回复您!非常感谢!

cumt-robin avatar Sep 30 '22 13:09 cumt-robin