Open BePo65 opened 3 years ago
IMHO it's a babel theme. The (esm) source clearly has a class with a constructor. But it seams that node will not recognize the code generated by babel as a class.
So for the esm version in dayjs/esm
I am asking myself, why do you let babel transform esm to esm? But probably I just don't get the point :-)
Same problem happening for me now too.
New React project made via create-react-app (which uses webpack), with antd as the UI library. Their datepicker uses dayjs for some reason, and it is not working because of this exact problem - "dayjs is not a constructor"
Specifically:
dayjs__WEBPACK_IMPORTED_MODULE_14___default(...).Dayjs is not a constructor
TypeError: dayjs__WEBPACK_IMPORTED_MODULE_14___default(...).Dayjs is not a constructor
at DrawRouteDetails (http://localhost:3000/static/js/bundle.js:6912:40)
at renderWithHooks (http://localhost:3000/static/js/bundle.js:151075:22)
at updateFunctionComponent (http://localhost:3000/static/js/bundle.js:153955:24)
at beginWork (http://localhost:3000/static/js/bundle.js:155667:20)
at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/bundle.js:140671:18)
at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/bundle.js:140715:20)
at invokeGuardedCallback (http://localhost:3000/static/js/bundle.js:140772:35)
at beginWork$1 (http://localhost:3000/static/js/bundle.js:160636:11)
at performUnitOfWork (http://localhost:3000/static/js/bundle.js:159884:16)
at workLoopSync (http://localhost:3000/static/js/bundle.js:159807:9)
I had the same issue. Use const demo = dayjs();
instead of const demo = new dayjs();
Looking at the source, there is a definition for a class named
Dayjs
with a constructor. Even in the type definition files I can see this class in the namespace dayjs. And in line 48 of 'dayjs/esm/index.js'return new Dayjs(cfg);
is used.But when I try to use
const demo = new dayjs.Dayjs()
orconst demo = new dayjs()
all I get when running the program is an error that saysTypeError: dayjs.Dayjs is not a constructor
no matter if I useconst dayjs = require('dayjs');
orimport dayjs from 'dayjs';');
orimport dayjs from 'dayjs/esm';');
So the question is: what am I doing wrong; where is my misinterpretation of the source / type definition.
Information