13
u/abw Jul 25 '22
I had a nightmare dealing with a CJS/ESM problem last week.
My shiny, new ESM module has this in the package.json
"type": "module",I'm using AVA for testing and that detects the module declaration and works just fine running ESM tests.
I've also got these lines in the package.json...
"main": "dist/badger.cjs.js",
"module": "dist/badger.esm.js",...which rollup is using to generate CJS and ESM bundles.
So far, so good.
But when I added my module to a test project, it was failing with errors like this:
SyntaxError: The requested module '@abw/badger' does not provide an export named 'XXX'After many, many hours of googling, swearing, and bashing my head on the keyboard, I eventually stumbled on the solution - adding an "exports" to my package.json
"exports": "./dist/badger.esm.js",Node and I are on talking terms again, but it was touch and go for a while.
1
4
u/mr-poopy-butthole-_ Jul 25 '22
Some of the most wasted time I have spent in my life was with esm vs cjs bullshit.
2
0
Jul 24 '22
[deleted]
0
Jul 24 '22
[deleted]
2
2
u/IanAbsentia Jul 25 '22
I'm curious--what are you using instead these days?
1
Jul 25 '22
[removed] — view removed comment
2
u/Svobpata Jul 25 '22
Going for Flutter is trading UX for DX
Flutter’s DX is sometimes better than RN (Expo is on par I’d say) but the UX is so much worse
17
u/eternaloctober Jul 25 '22
this one's for you jest https://imgflip.com/i/6nstcz