Feature request: add commonjs and esm exports
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.
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.
Did you guys find a workaround? @ericallam @Spudfellah
@palfaro91 unfortunately the only way at the moment is to use dynamic imports.
Going back to ^1.13.3 is a temporary solution
@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
Also happy to submit a PR to support both ESM and CommonJS.
@jacquesg There's a PR open here: https://github.com/flightcontrolhq/superjson/pull/301
Tried a few different hacks but ended up downgrading to ^1.13.3 for now.
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"
]
}
Going back to ^1.13.3 is a temporary solution
This is the only solution that worked for me in nx monorepo.