question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

require doesn't support `default` exports in ES Modules in Webpack

See original GitHub issue

Day.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:closed
  • Created 5 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
iamkuncommented, Feb 14, 2019

@githoniel

In v1.8.6, I changed module back to the umd version. This might could solve this issue, but of course not a good practice.

"main": "dayjs.min.js",
"module": "dayjs.min.js",

However, we could still use the ESM version like this

import dayjs from 'dayjs/esm'
0reactions
iamkuncommented, Jan 5, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found