Dayjs: No default export (1.8.4)

Created on 6 Feb 2019  路  22Comments  路  Source: iamkun/dayjs

With v1.8.4 I got the following error:

import dayjs from 'dayjs';

Module '".../node_modules/dayjs/index"' has no default export.

Most helpful comment

Yes, I'm getting this. I don't have time to setup a toy repo and everything, but will post some screenshots of what I'm seeing:

Using:

import * as dayjs_ from 'dayjs';
console.log('daysjs before: ', dayjs)
debugger;
const dayjs = (dayjs_).default || dayjs_;
console.log('daysjs after: ', dayjs)
debugger;

I see it's undefined until I apply the .default workaround others have mentioned:

image

The logs in ^ should show that just doing import * as dayjs_ from 'dayjs'; in webpack results in undefined鈥攍ooks like it's considering it a default export.

But even when I attempt to use es6 import default approach (e.g. import dayjsAsDefault from 'dayjs';), it doesn't get fully resolved. This is after such import:

image

and dayjsAsDefault is undefined

Personally, I'd reopen this until it's proven to work with Webpack given the popularity of that bundler but up to maintainer of course ;) For now, we'll all have imports with comments pointing to this issue

All 22 comments

try import * as dayjs from 'dayjs' then

It causes webpack error: dayjs__WEBPACK_IMPORTED_MODULE_0__ is not a function.

With 1.8.3 the import dayjs from 'dayjs'; format works.

Would you please set up a reproduction repo ?

This is related to #477. A commonjs-exported module works the same when doing import foo from 'foo' as import * as foo from 'foo'. However, native ES6 modules see these as different things, and you need an explicit export default foo in order to make it work. This seems like a regression to me, since this is a breaking change in a patch release.

@Tvrqvoise Well my fault, I did not realize that added a module entry would have such big side effect.

Try hotfix v1.8.5, contains @Tvrqvoise's fix, hope this will help.

Not works :/

Basic code for check the import failure:

https://github.com/petrot/dayjs-bug-test

The way around this issue was to do the following:

import * as dayjs_ from 'dayjs';
const dayjs = (dayjs_).default || dayjs_;

granted the export should be fix so we do not have to do this.

@petrot thanks

@petrot I could reproduce this in your test repo, but in a simple TypeScript project I created with dayjs v1.8.5, import * as dayjs from 'dayjs' works well.

I don't know much about Angular, and just thought, could this issue related to Angular configuration?

Or maybe you could simplify your test repo without using Angular.

@iamkun 1.8.5 is broken with webpack

const dayjs = require('dayjs') // works with 1.8.4 but broken in 1.8.5

const dayjs = require('dayjs').default // works with 1.8.5

you may need to check this https://github.com/webpack/webpack/issues/4742

@githoniel yes, and I believe this is a bug in webpack.
It load the module entrance not only in import, but alsorequire

@githoniel #492 I opened a new issue related to this

@petrot Seems fixed after upgrading dayjs to v1.8.6 in your test repo.

@iamkun 1.8.6 works well, thank you!

IMO this shouldn't be closed. Pre-1.8.4 behaviour (import dayjs from "dayjs";) is still broken and this is a BC break. We are using dayjs in several in-house apps and packages which depend on each other, and this has just broken our entire stack with a single dependency update. We would really appreciate not having to spend a whole day editing our import code / editing package.json to use a fixed 1.8.3 version on every single app/package.

Would you please consider going the extra mile to try and make import and require behaviours both work as intended? I can try to help if you give me a few pointers about the specific problem. Thanks a ton!

@neemzy I'm sorry that there is some problem from 1.8.0 to 1.8.5, but I think we've fixed it in v1.8.6.
And in v1.8.6 both require and import should all work as expected. There's no BC in these versions, so I think it is safe to upgrade to v1.8.6 from v1.8.x.
Let me know if the problem continues.

Hi there,

I'm getting the error: "Module '".../angular/node_modules/dayjs/plugin/isBetween"' has no default export.

Version: 1.8.14 on Angular CLI 7.3.8. Any solutions or should I do a combination of isBefore and isAfter in the meantime?

@iamkun Version 1.8.15/1.8.16 on Angular 6.0.8. import dayjs from 'dayjs'; throw ERROR TS1192.

@luvletterldl a test repo, please.

Yes, I'm getting this. I don't have time to setup a toy repo and everything, but will post some screenshots of what I'm seeing:

Using:

import * as dayjs_ from 'dayjs';
console.log('daysjs before: ', dayjs)
debugger;
const dayjs = (dayjs_).default || dayjs_;
console.log('daysjs after: ', dayjs)
debugger;

I see it's undefined until I apply the .default workaround others have mentioned:

image

The logs in ^ should show that just doing import * as dayjs_ from 'dayjs'; in webpack results in undefined鈥攍ooks like it's considering it a default export.

But even when I attempt to use es6 import default approach (e.g. import dayjsAsDefault from 'dayjs';), it doesn't get fully resolved. This is after such import:

image

and dayjsAsDefault is undefined

Personally, I'd reopen this until it's proven to work with Webpack given the popularity of that bundler but up to maintainer of course ;) For now, we'll all have imports with comments pointing to this issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vaquel picture vaquel  路  3Comments

ljmerza picture ljmerza  路  3Comments

fes300 picture fes300  路  5Comments

paraself picture paraself  路  3Comments

eugeneoshepkov picture eugeneoshepkov  路  3Comments