flightcontrolhq / superjson

Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
https://www.flightcontrol.dev?ref=superjson
MIT License
4.01k stars 87 forks source link

fix: TypeError: SuperJSON is not a constructor #250

Closed juliusmarminge closed 1 year ago

juliusmarminge commented 1 year ago

"Fixes" https://github.com/blitz-js/superjson/pull/247#issuecomment-1637631294

import { SuperJSON } from "superjson"
const superjson = new SuperJSON();

now works. default import still broken though

juliusmarminge commented 1 year ago

Not optimal since it doesn't fix the default import, but works as a workaround 🤷🏼‍♂️

Tested using yalc locally and linking to a separate package outside the superjson repo

Skn0tt commented 1 year ago

That's a good workaround, I guess. The problem with the default export boils down to the fact that apparently, SuperJSON in this context is of type Module, not the class that we expect it to be. So this should also work:

import SuperJSON from "superjson"

new SuperJSON.default()
Skn0tt commented 1 year ago

Let's get this merged 🤷

juliusmarminge commented 1 year ago

So this should also work:

import SuperJSON from "superjson"

new SuperJSON.default()

While that might work in runtime, you get typeerrors. Somewhere the type is wrong I guess? Bundlers are weird...

CleanShot 2023-07-17 at 11 24 35@2x
Skn0tt commented 1 year ago

Published as part of https://github.com/blitz-js/superjson/releases/tag/v1.13.1.

juliusmarminge commented 1 year ago

And this errors with the same error:

import * as SuperJSON from 'superjson'

export const superjson = new SuperJSON.default({
    dedupe: true,
})
CleanShot 2023-07-17 at 11 27 45@2x
juliusmarminge commented 1 year ago

Published as part of https://github.com/blitz-js/superjson/releases/tag/v1.13.1.

Can confirm it works straight from node_modules (no local linked package) 👍🏼