Skip to content
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

ESM + CJS builds on the 3.x version #54

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

ESM + CJS builds on the 3.x version #54

wants to merge 3 commits into from

Conversation

philcockfield
Copy link
Owner

@philcockfield philcockfield commented Jul 24, 2024

FIX for #49 , #52, #53


Solution idea provided by conorfuller within #52

This is a Node 20/Next 14 based application and we are using a commonjs environment and am unable to switch easily to use ESM. Is it possible to add default exports to the package.json for increased module support? As has been done here for next/auth nextauthjs/next-auth@b1a8102


NB: does not work.

Solution approach:

  • alternative CJS + ESM typescript builder → [npm] pipeline
  • dnt

npm i [email protected].<latest>

Test sequence (CJS):

// filename: index.js
const fsc = require('file-system-cache');
node index.js

Test sequence (ESM):

// filename: index.js
import fsc from "file-system-cache";

const cache = fsc();
console.log(cache);
node index.js

@philcockfield philcockfield changed the title CJS support post 3.x (ESM) ESM + CJS builds Jul 25, 2024
@philcockfield philcockfield changed the title ESM + CJS builds ESM + CJS builds on the 3.x version Jul 25, 2024
@JessicaSachs
Copy link

Was 3.0.0-alpha.7 released from this PR? I'm having issues with dynamic requires happening in ESM (probably a dep of yours) and I'll report/write them up in the right place, but if it is this PR and you were planning on merging it, I wanted to give you a heads up.

@philcockfield
Copy link
Owner Author

philcockfield commented Aug 9, 2024

Hey @JessicaSachs 👋 , this is the ESM (update) nightmare the world is facing. ESM is 10 years old now, and a proper standard - libraries forcing the upgrade like this is the right move IMO, but I also understand the frustration of it.

I hit this (personally, on other projects) a couple of years ago when high-quality libs started publishing ESM only version, and common-js broke, and at that point I bit the bullet and updated all my mono-repos to full ESM (no common-js).

This particular change on this repo came in via one of the Storybook maintainers, and has now inflicted this same problem on all the upstream dependents on this little lib.

I'm deciding what to do here...Node has been terrible, dragging it's feet on this ESM thing. But as an industry, we really do need to get off all the legacy "non-standards" now we have the one "actual", proper module standard for JS.

I'm low key thinking of refactoring this over into Deno, and just having a more modern, "standards based" runtime do all the legacy module bundling (aka. common-js).

--
PS: The prior 2.x version still works on common-js.
PPS: I see you work on "vitest" ← utterly beautiful test suite system!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants