iamkun / iamkun/dayjs

dayjs plugins not recognized when imported in a separate location

Open
#1,797 2 comments 4 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
A clear and concise description of what the bug is.

I have a dayjs config file where I extend all the plugins I need for the project:

`dayjs.ts`
```
import utc from "dayjs/plugin/utc";
import customParse from "dayjs/plugin/customParseFormat";
import timezone from "dayjs/plugin/timezone";
import minMax from "dayjs/plugin/minMax";
import dayjs from "dayjs";
import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
import duration from "dayjs/plugin/duration";

dayjs.extend(utc);
dayjs.extend(customParse);
dayjs.extend(timezone);
dayjs.extend(minMax);
dayjs.extend(isSameOrAfter);
dayjs.extend(isSameOrBefore);
dayjs.extend(duration);
dayjs.tz.setDefault("America/Toronto");

export default dayjs;
```

I then import dayjs from this file. However, the plugins are not being recognized when used in a Next JS project:

`TypeError: dayjs__WEBPACK_IMPORTED_MODULE_0__.default.duration is not a function`

**Expected behavior**
A clear and concise description of what you expected to happen.

The plugins should be recognized properly.

**Information**
- Day.js Version [e.g. v1.0.0] v1.10.7
- OS: [e.g. iOS] Windows 10
- Browser [e.g. chrome 62] Chrome 98
- Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)] GMT -05:00

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.