-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue when using esm import #593
Comments
A re-porduction link or repo will be better |
I get the same issue. I think it might be related to this: #598 |
Also still having issues with the plugin imports in angular project. But when I need to use plugins, I import with
I've tried multiple variations of the import statements, but none have seemed to work. I would love to switch from moment.js to dayjs, but I won't be able to use this package until I can use the plugin functions. |
I got the same issue with localization. At the very beginning of my GatsbyJS site I do: const dayjs = require('dayjs')
require('dayjs/locale/de')
dayjs.locale('de') Inside my react script I tried these two: import dayjs from 'dayjs'
const date = new window.Date()
console.log(date) // Tue Oct 01 2019 00:00:00 GMT+0200 (Mitteleuropäische Sommerzeit)
console.log(dayjs(date)) // {$L: "en", $d: Tue Oct 01 2019 00:00:00 GMT+0200 (Mitteleuropäische Sommerzeit), $y: 2019, $M: 9, $D: 1, …}
console.log(dayjs(date).format()) // 2019-10-01T00:00:00+02:00
console.log(dayjs(date).format('LL')) // LL
console.log(dayjs(date).locale('de')) // {$L: "de", $d: Tue Oct 01 2019 00:00:00 GMT+0200 (Mitteleuropäische Sommerzeit), $y: 2019, $M: 9, $D: 1, …}
console.log(dayjs(date).format('LL')) // LL
console.log(dayjs(date).locale('de').format('LL')) // LL This just outputs |
Solve by using "dayjs": "^1.8.16" Add this in tsconfig.json
And use like this
|
for posterity, for non-TS setups, if calling the |
Got the same issue when using |
For posterity: I have the same issue and none of the fixes above worked. import dayjs from 'dayjs';
import durationPlugin from 'dayjs/plugin/duration';
dayjs.extend(durationPlugin); In my environment I'm adding No way to make it work, I was forced to move the registration in the main chunk. |
If anyone is having a similar issue with node I just had to add the extension to the utc import. I'm running nodejs 14.x TL;DR import dayjs from "dayjs";
import utc from "dayjs/plugin/utc.js"; // <------ Notice the .js
dayjs.extend(utc) |
This is the correct answer for node |
How can I export dayjs.extend(isToday)? Sorry I am a beginner and I am trying to export isToday() to multiple files. |
Try stack overflow. Your question is off topic. |
For me, I was able to get this working with the following:
With TypeScript version I use Vite with the following TypeScript config: ...
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
... |
Describe the bug
A clear and concise description of what the bug is.
So I have two issue when using "dayjs": "1.8.14"
The first one if I'm using import like this
My code is working perfectly fine but angular Cli will throw error
Module "node_modules/dayjs/index" has no default export.
Then I change my code to
Then the angular cli not throw any error but the code is not working and I have this error
What have i done wrong.
The text was updated successfully, but these errors were encountered: