dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

How to set dayjs global config in next14

Open BoubleJ opened this issue 10 months ago • 4 comments

Describe the bug

I tried to apply global config by referring to the GitHub issue.

but it does not work.

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


//app/layout.tsx

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

//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
//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

BoubleJ avatar Jun 10 '25 02:06 BoubleJ

Bump. Same issue in client components.

localpath avatar Aug 16 '25 03:08 localpath

Having same issue in client components.

Techfourthparty avatar Aug 16 '25 03:08 Techfourthparty

Same, doesnt work in client components

OndrejHj04 avatar Sep 15 '25 15:09 OndrejHj04

same, any update?

sp0033212000 avatar Nov 10 '25 19:11 sp0033212000