iamkun / iamkun/dayjs

How to set dayjs global config in next14

Open
#2,887 5 comments 3 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**

I tried to apply global config by referring to the [GitHub issue](https://github.com/iamkun/dayjs/issues/1577).

but it does not work.

I'm using next.js 14 app router. Extending day.js globally does not work.

```ts

//app/layout.tsx

import React, { ReactNode } from 'react';
import type { Metadata, Viewport } from 'next';
import '@/src/common/utils/dayjs';
```

```ts

//src/common/utils/dayjs

import dayjs from 'dayjs';
import ko from 'dayjs/locale/ko';
import timezone from 'dayjs/plugin/timezone';
import utc from 'dayjs/plugin/utc';
import isoWeek from 'dayjs/plugin/isoWeek';
import duration from 'dayjs/plugin/duration';

dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.extend(isoWeek);
dayjs.extend(duration);

dayjs.locale(ko);

dayjs.tz.setDefault('Asia/Seoul');

export default dayjs
```

```ts
//tsconfig.ts

{
"compilerOptions": {
"target": "ES2018",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"allowSyntheticDefaultImports": true,
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": [
"./*"
]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}

```

**Expected behavior**
Setup instructions on how to setup dayjs once globally and have it recognize all used plugin types globally in next 14.

**Information**
- Day.js Version : 1.11.13

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.