require doesn't support `default` exports in ES Modules in Webpack
See original GitHub issueDay.js added module
in package.json
in v1.8.1+ , in order to support ES Modules.
However, there’s some unexpected behavior while using commonJS require
with webpack
And there a discussion from webpack
here, https://github.com/webpack/webpack/issues/4742
const dayjs = require('dayjs') // works with 1.8.0 -
const dayjs = require('dayjs') // broken with 1.8.1 +
const dayjs = require('dayjs').default // works with 1.8.1 +
Note: add .default
is just a temporary workaround, and it’s still a bug with webpack we think. Since default
is an artifact of ES Modules and should not appear in CJS requires
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (9 by maintainers)
Top Results From Across the Web
Bug: require() doesn't support `default` exports in ES Modules ...
In webpack 1.x, this picks up the CommonJS file defined in main . In webpack 2.x, this loads the module file and sets...
Read more >Module Methods - webpack
Make all exports from the dependency available in the current scope. The require label can occur before a string. The dependency must export...
Read more >Can't require() default export value in Babel 6.x - Stack Overflow
TL;DR. You have to use const app = require('./app').default; app();. Explanation. Babel 5 used to have a compatibility hack for export default :...
Read more >How to transpile ES modules with webpack and Node.js
Learn how webpack interacts with and supports ES modules in this deep dive tutorial ... Also note that we can have default exports...
Read more >ES6 Modules: Getting Started Gotchas | by Matt LaGrandeur
Edge — actually doesn't throw an error, but also fails to load the module :-\ It is good practice to think about what...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@githoniel
In v1.8.6, I changed
module
back to theumd
version. This might could solve this issue, but of course not a good practice.However, we could still use the
ESM
version like thisAfter a lot of issues related to the ESM module entry.
A final decision here: https://github.com/iamkun/dayjs/pull/1314
This package will not ship with
package.json
module entry.