Issue when using esm import
See original GitHub issueDescribe the bug A clear and concise description of what the bug is. So I have two issue when using “dayjs”: “1.8.14”
The first one if I’m using import like this
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import LocalizedFormat from "dayjs/plugin/localizedFormat";
dayjs.utc(lockedAt).locale(localize) .format("lll");
My code is working perfectly fine but angular Cli will throw error Module “node_modules/dayjs/index” has no default export.
Then I change my code to
import dayjs from "dayjs/esm";
import utc from "dayjs/esm/plugin/utc";
import LocalizedFormat from "dayjs/esm/plugin/localizedFormat";
Then the angular cli not throw any error but the code is not working and I have this error
Cannot read property ‘formats’ of undefined
What have i done wrong.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:13
Top Results From Across the Web
[Question] ESM import issues when moving to Angular 13
We are moving to Angular 13 and are now finding that out existing E2E tests (stored in an e2e folder) are failing because...
Read more >Avoid these issues when using new ECMAScript modules ...
Most typescript applications importing commonjs modules should turn on esModuleInterop in their tsconfig file. Then you can just use a “normal” ...
Read more >Getting Started with (and Surviving) Node.js ESM
Now let's take a look at actually doing imports in our code. As you'd expect, importing ESM from ESM and CommonJS from CommonJS...
Read more >require() of ES modules is not supported when importing ...
node-fetch is an ESM-only module - you are not able to import it with require. We recommend you stay on v2 which is...
Read more >import - JavaScript - MDN Web Docs - Mozilla
The static import declaration is used to import read-only live bindings which are exported by another module. The imported bindings are ...
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 Free
Top 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

Solve by using “dayjs”: “^1.8.16”
Add this in tsconfig.json
"allowSyntheticDefaultImports": true,And use like this
If anyone is having a similar issue with node I just had to add the extension to the utc import. My project is vanilla js and it kept trying to import the typescript version of the utc plugin.
I’m running nodejs 14.x
TL;DR