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

Feature request: add commonjs and esm exports #299

Open
ericallam opened this issue Sep 19, 2024 · 8 comments · May be fixed by #301
Open

Feature request: add commonjs and esm exports #299

ericallam opened this issue Sep 19, 2024 · 8 comments · May be fixed by #301

Comments

@ericallam
Copy link

Currently superjson does not export commonjs, only ESM. It would be great to support both formats. Our package that we use superjson in supports both formats and having superjson be ESM only causes some issues. It's really easy these days to create a dual-package using something like tshy (which is what we use). If you are open to it, I'd be happy to create a PR.

@hashwarp
Copy link

hashwarp commented Oct 3, 2024

Ya, I feel like whoever made this change isn't living in reality. ESM-only simply doesn't work for any app of medium complexity.

@acheronfail acheronfail linked a pull request Oct 8, 2024 that will close this issue
@palfaro91
Copy link

Did you guys find a workaround? @ericallam @Spudfellah

@ericallam
Copy link
Author

@palfaro91 unfortunately the only way at the moment is to use dynamic imports.

@harijoe
Copy link

harijoe commented Nov 5, 2024

Going back to ^1.13.3 is a temporary solution

@jacquesg
Copy link

@palfaro91 unfortunately the only way at the moment is to use dynamic imports.

That kinda works, but it doesn't work once you're using jest

@jacquesg
Copy link

Also happy to submit a PR to support both ESM and CommonJS.

@aMoniker
Copy link

@jacquesg There's a PR open here: #301

Tried a few different hacks but ended up downgrading to ^1.13.3 for now.

@PlanetTeamSpeakk
Copy link

PlanetTeamSpeakk commented Feb 27, 2025

Tried to use github:acheronfail/superjson#support-cjs, but this did not work. The ESM/CJS error was replaced with one complaining about missing type declarations. The approach that did work, however, was cloning the repo from the PR and building the support-cjs branch and then using the dist-cjs folder as the source for superjson (in my case, the dependency entry ended up being file:../local_superjson where local_superjson is a symlink to the dist-cjs folder of the superjson fork).
This will just be my temporary solution until that PR is merged.

Edit:
Should also note I had to add a package.json file to the folder. The file looks like this:

{
  "version": "2.2.1",
  "name": "superjson",
  "license": "MIT",
  "type": "commonjs",
  "types": "./index.d.ts",
  "main": "./index.cjs",
  "browser": "./index.cjs",
  "exports": {
    ".": {
      "types": "./index.d.ts",
      "browser": "./index.cjs",
      "import": "./index.cjs",
      "require": "./index.cjs",
      "default": "./index.cjs"
    }
  },
  "files": [
    "*.js",
    "*.cjs",
    "*.d.ts"
  ]
}

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 a pull request may close this issue.

7 participants