Skip to content
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

No default export (1.8.4) #480

Closed
petrot opened this issue Feb 6, 2019 · 22 comments
Closed

No default export (1.8.4) #480

petrot opened this issue Feb 6, 2019 · 22 comments

Comments

@petrot
Copy link

petrot commented Feb 6, 2019

With v1.8.4 I got the following error:

import dayjs from 'dayjs';

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

@iamkun
Copy link
Owner

iamkun commented Feb 6, 2019

try import * as dayjs from 'dayjs' then

@petrot
Copy link
Author

petrot commented Feb 6, 2019

It causes webpack error: dayjs__WEBPACK_IMPORTED_MODULE_0__ is not a function.

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

@iamkun
Copy link
Owner

iamkun commented Feb 6, 2019

Would you please set up a reproduction repo ?

@Tvrqvoise
Copy link
Contributor

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 added a commit to Tvrqvoise/dayjs that referenced this issue Feb 6, 2019
@iamkun
Copy link
Owner

iamkun commented Feb 7, 2019

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

iamkun pushed a commit that referenced this issue Feb 7, 2019
## [1.8.5](v1.8.4...v1.8.5) (2019-02-07)

### Bug Fixes

* Add en-gb locale ([#478](#478)) ([508c3a7](508c3a7))
* **module:** transpile everything except ES6 modules in the 'module' entrypoint ([#477](#477)) ([#480](#480)) ([#482](#482)) ([767017d](767017d))
* update customParseFormat plugin support hh:mm ([54947cc](54947cc)), closes [#484](#484)
* Update module in package.json ([5c5a7a0](5c5a7a0))
@iamkun
Copy link
Owner

iamkun commented Feb 7, 2019

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

@petrot
Copy link
Author

petrot commented Feb 7, 2019

Not works :/

@petrot
Copy link
Author

petrot commented Feb 8, 2019

Basic code for check the import failure:

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

@alvaro450
Copy link

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.

@iamkun
Copy link
Owner

iamkun commented Feb 8, 2019

@petrot thanks

@iamkun
Copy link
Owner

iamkun commented Feb 11, 2019

@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.

@githoniel
Copy link

@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 webpack/webpack#4742

@ghost
Copy link

ghost commented Feb 12, 2019

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

@iamkun
Copy link
Owner

iamkun commented Feb 12, 2019

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

@iamkun
Copy link
Owner

iamkun commented Feb 14, 2019

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

@petrot
Copy link
Author

petrot commented Feb 15, 2019

@iamkun 1.8.6 works well, thank you!

@iamkun iamkun closed this as completed Feb 15, 2019
@neemzy
Copy link

neemzy commented Feb 15, 2019

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!

@iamkun
Copy link
Owner

iamkun commented Feb 15, 2019

@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.

@elliotwesoff
Copy link

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?

@luvletterldl
Copy link

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

@iamkun
Copy link
Owner

iamkun commented Aug 28, 2019

@luvletterldl a test repo, please.

@roblevintennis
Copy link

roblevintennis commented Sep 5, 2019

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—looks 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

andrewhood125ruhuc added a commit to andrewhood125ruhuc/SidRH2 that referenced this issue May 10, 2022
## [1.8.5](iamkun/dayjs@v1.8.4...v1.8.5) (2019-02-07)

### Bug Fixes

* Add en-gb locale ([#478](iamkun/dayjs#478)) ([508c3a7](iamkun/dayjs@508c3a7))
* **module:** transpile everything except ES6 modules in the 'module' entrypoint ([#477](iamkun/dayjs#477)) ([#480](iamkun/dayjs#480)) ([#482](iamkun/dayjs#482)) ([767017d](iamkun/dayjs@767017d))
* update customParseFormat plugin support hh:mm ([54947cc](iamkun/dayjs@54947cc)), closes [#484](iamkun/dayjs#484)
* Update module in package.json ([5c5a7a0](iamkun/dayjs@5c5a7a0))
andrewhood125ruhuc added a commit to andrewhood125ruhuc/SidRH2 that referenced this issue May 10, 2022
## [1.8.5](iamkun/dayjs@v1.8.4...v1.8.5) (2019-02-07)

### Bug Fixes

* Add en-gb locale ([#478](iamkun/dayjs#478)) ([508c3a7](iamkun/dayjs@508c3a7))
* **module:** transpile everything except ES6 modules in the 'module' entrypoint ([#477](iamkun/dayjs#477)) ([#480](iamkun/dayjs#480)) ([#482](iamkun/dayjs#482)) ([767017d](iamkun/dayjs@767017d))
* update customParseFormat plugin support hh:mm ([54947cc](iamkun/dayjs@54947cc)), closes [#484](iamkun/dayjs#484)
* Update module in package.json ([5c5a7a0](iamkun/dayjs@5c5a7a0))
splashwizard pushed a commit to splashwizard/tracking-time that referenced this issue Oct 21, 2024
## [1.8.5](iamkun/dayjs@v1.8.4...v1.8.5) (2019-02-07)

### Bug Fixes

* Add en-gb locale ([#478](iamkun/dayjs#478)) ([508c3a7](iamkun/dayjs@508c3a7))
* **module:** transpile everything except ES6 modules in the 'module' entrypoint ([#477](iamkun/dayjs#477)) ([#480](iamkun/dayjs#480)) ([#482](iamkun/dayjs#482)) ([767017d](iamkun/dayjs@767017d))
* update customParseFormat plugin support hh:mm ([54947cc](iamkun/dayjs@54947cc)), closes [#484](iamkun/dayjs#484)
* Update module in package.json ([5c5a7a0](iamkun/dayjs@5c5a7a0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants