question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dayjs.extend() and dayjs.locale() result in an error when dayjs is imported from ESM bundle

See original GitHub issue

Describe the bug

Extending with plugins and setting locale doesn’t seem to work when using ESM bundle. Following code produces following errors when used in Angular Typescript project.

import * as dayjs from 'dayjs/esm';
import 'dayjs/esm/locale/en-gb';
import * as customParseFormat from 'dayjs/esm/plugin/customParseFormat';

dayjs.locale('en-gb');
dayjs.extend(customParseFormat);
"export 'extend' (imported as 'dayjs') was not found in 'dayjs/esm'
"export 'locale' (imported as 'dayjs') was not found in 'dayjs/esm'

The code above works fine when importing directly from dayjs instead of dayjs/esm.

Information

  • Day.js Version 1.9.6
  • Angular v10

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
shaykecommented, Jan 4, 2021

Now in 1.10.0 due to https://github.com/iamkun/dayjs/issues/313 These imports don’t work anymore since ESM is used by default:

import * as dayjs from 'dayjs/esm';
import 'dayjs/esm/locale/en-gb';
import * as customParseFormat from 'dayjs/esm/plugin/customParseFormat';

For now i’ve added an alias in my webpack config if anyone is interested as a workaround: 'dayjs$': path.resolve(path.join(__dirname, 'node_modules/dayjs/dayjs.min.js')),

1reaction
iamkuncommented, Nov 27, 2020

Seems a nice choice. We’ll think about that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Complete Guide to Day.js - Mirza Leka - Medium
To run Day.js, simply type dayjs() and this will generate you a ... If you are importing a locale that doesn't exist you'll...
Read more >
Why is dynamic importing of dayjs not working in typescript?
In my typescript code I want to use dayjs and import dynamically 'dayjs/locale/${language}' where language comes from AcceptLanguageList above. import React, { ...
Read more >
How to use the dayjs.extend function in dayjs - Snyk
To help you get started, we've selected a few dayjs examples, based on popular ways it is used in public projects. ; from...
Read more >
dayjs | Yarn - Package Manager
1.11.7 (2022-12-06). Bug Fixes. Add locale (zh-tw) meridiem (#2149 (1e9ba76); update fa locale (#2151 (1c26732). 1.11.6 (2022-10-21). Bug Fixes.
Read more >
dayjs-example - CodeSandbox
Activating extension 'vscode.typescript-language-features' failed: Could not find bundled tsserver.js.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found