-
-
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
require doesn't support default
exports in ES Modules in Webpack
#492
Comments
@iamkun no, this is what was specified in your source code, here. |
@mweststrate Yes, that's why we have two bundles And webpack just load the |
That is what one would expect right? Otherwise your lib might end up twice
in the bundle. The problem seems that your minified bundle does _not_ have
a `.default` export, so effectively you are shipping a different API in
your commonJS version than in your ESM version
Op di 12 feb. 2019 om 16:17 schreef iamkun <notifications@github.com>:
… @mweststrate <https://github.com/mweststrate> Yes, that's why we have two
bundles main: /dayjs.min.js is the umd bundle for commonjs, while module:
/esm/index.js is for the ESM.
And webpack just load the module: /esm/index.js no matter it is require
or import.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#492 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhEu-lpXqJFSROf5namTmKIpxs_Leks5vMtr1gaJpZM4a2JU7>
.
|
|
You cannot, strictly speaking, support the old CJS interface with ESM exports since it would require making your ESM namespace the |
@Tvrqvoise I don't agree. Seems some of the imported utils and constants is tree-shakable. |
@mweststrate @githoniel And the main problem here is webpack is using the wrong file. |
@xxyx there's only one export in the library, everything else is referred to by it. Current DCE techniques can't trim that out. I've been wrong before though, if you have an example of something that you think could be tree-shook, let me know. |
@Tvrqvoise Seems we just do Although it is not real ESM ... |
@iamkun, yes, but you'll still have the |
In my test, if changed like this, CJS require will be fine.
|
@iamkun could you release a new version to resolve this? |
In v1.8.6, I changed
However, we could still use the
|
In version 1.8.27, the type declaration file for 'dayjs/esm' is missing. |
According to webpack/webpack#4742,
if you have to use
|
After a lot of issues related to the ESM module entry. A final decision here: #1314 This package will not ship with |
Day.js added
module
inpackage.json
in v1.8.1+ , in order to support ES Modules.However, there's some unexpected behavior while using commonJS
require
withwebpack
And there a discussion from
webpack
here, webpack/webpack#4742Note: add
.default
is just a temporary workaround, and it's still a bug with webpack we think. Sincedefault
is an artifact of ES Modules and should not appear in CJS requiresThe text was updated successfully, but these errors were encountered: