dayjs.extend() and dayjs.locale() result in an error when dayjs is imported from ESM bundle
See original GitHub issueDescribe 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:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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:
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')),Seems a nice choice. We’ll think about that.