-
-
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
TypeError: dayjs_1.default is not a function #475
Comments
same error here |
Bug confirmed. We changed index.d.ts from TS expert help wanted. |
Seems add |
What were the benefits of that change? Couple of reasons why to avoid default exports: |
Just released v1.8.4 to revert this change. Please remain using
in a TypeScript project. And discussion still welcome |
I also saw this issue when |
@tsiq-jeremy Your Day.js version and TS version, please. |
Ahh actually it was a bit more complicated I'm realizing then what I wrote. Basically when you have a library compiling with tsconfig I think I may write this all up in a separate issue, but I think a root cause to this is when using tsconfig Looks like adding |
This is an issue for me in a Next.js project. On the server side when rendering a React component I get:
Works on the client rendering cycle of Next.js but not the Node side. Adding the following to my
Using Have to use a different date library till this is resolved 😢 |
@danawoodman a reproduction demo repo, please? |
@iamkun I figured it out, it was because I imported the "relativeTime" extension in my entry point but didn't import it where I was using it. I just assumed that it would work at the entry point but moving it right next to the code in question fixed it: import dayjs from "dayjs"
import relativeTime from "dayjs/plugin/relativeTime"
dayjs.extend(relativeTime)
console.log(dayjs(new Date("jan 1, 2020").fromNow()) |
Had the same issue after update to webpack5, probably will help someone also: https://hinty.io/devforth/fix-webpack-imported-module-is-not-a-function-for-webpack5/ |
This exception is still thrown, when you use dayjs in tests triggered by Jest you get it sometimes even tho the app in real-time works perfectly. Weird issue |
Same issue for me, the weird thing is that in the first time is working, i don't know why is show me this error. |
@AndresAusecha exactly that, my tests fail because of that error.
|
Can I put a bounty on this bug ? I set it to 100$
|
@iamkun Why this issue closed? |
|
This repo feels forsaken. |
So they should be set to false to fix the issue? |
I'm still getting the same error in end of 2021. Any new ideas? |
Yes, I moved to Luxon, bigger package size but at least it doesn't f*** up my tests. |
At least for me the issue was importing dayjs directly
Don't know why the types in the app worked but jest behaviour also seems correct. |
Using default imports
in the tested module instead |
I was facing this issue as well. I added |
I am trying this in a React project (JS not TS) and it does not work. I get the error My code is: |
Facing similar issue My code is import dayjs from 'dayjs';
const createdAt = dayjs.utc(review.createdDt || '') TypeError: dayjs__WEBPACK_IMPORTED_MODULE_1__.utc is not a function tsconfig is already had dayjs version 1.10.4 |
I need to buy you a beer |
I have tried all the suggestions in this thread. Warning to anyone trying to publish a typescript npm package artifact in azure with this. It works like a charm in the artifact repo, but once distributed to your development-repo it just wont work anymore. Just use a different library. |
For anyone else coming to this with a similar issue to me, my problem was that the |
This works for me when I export the plugins along with the default. // dayjs.ts
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import isTomorrow from 'dayjs/plugin/isToday';
import isToday from 'dayjs/plugin/isTomorrow';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(utc);
dayjs.extend(isToday);
dayjs.extend(isTomorrow);
dayjs.extend(relativeTime);
export {
dayjs,
utc, isToday, isTomorrow, relativeTime, // important to not get compiling errors when using these plugins
}; This then works in another file // anotherFile.js
import { dayjs } from './dayjs';
dayjs.utc(); |
@iamkun any news about update and fix this bug dude? Don't make us look for another package!😥 |
Any update on fixing this? I'm working in a JS React Native project. This is really quite frustrating.
|
Same error with version v1.11.6! |
Same issue here, in a React project: |
|
I now get Update: I have fixed it: |
same error here, nothing works |
Still facing this issue. Impossible to use jest + ts while using extend.
when I use
I get a TS error. #1132 (comment) If I then also add, in tsconfig.json:
I get:
The only way around was to move all my dayJS calls to wrapper functions in a separate file and mock each and every single one. This is unsustainable. |
is there a way to skip type errors? |
wondering how to do unit tests with dayjs, I got dayjs_1.default or dayjs_1.default.extend is not a function error no matter how I try: jest.mock('dayjs', () => { |
I'm using My tests were failing because I have a dependency on rc-picker which also depends on dayjs. To fix, I installed dayJs as a devDependency, and mapped it to the correct entrypoint file in my
|
When updating the dayjs package from 1.8.0 to 1.8.3, I'm getting this error.
I changed my import from
import * as dayjs from 'dayjs';
toimport dayjs from 'dayjs';
which let me compile, but this error what this result.Here is the line of code for the error:
const today = dayjs().format('YYYY-MM-DD');
The text was updated successfully, but these errors were encountered: