TypeError: Cannot call a class constructor without |new| index - TypedJSON error
0xjjpa opened this issue · comments
When using writeJson(SignatureProofList, attestation.proof)
on a browser environment, I get the error TypeError: Cannot call a class constructor without |new| index
. For context, I'm using zkp-ecdsa
in the following application within nextjs
and after compiling it for "production", the code no longer works showing that error. During "development" (i.e. next dev
) the code shows no issue so this is likely a JavaScript error after an improper transpiling from TypeScript.
FWIW I tried updating the same tsconfig.json
, the same typescript
version, importing reflect-metadata
, using Proxy
to wrap the Type and then pass the instance to the writeJson
, using directly TypedJSON.stringify
, JSON.stringify
, and nothing worked.
Would it be possible to give a try to run the read/write|Json
code against a browser runner? I've seen most of this code in action already used in browsers, but just the serializing part might be broken.
This is the exact line and the exact values where the error kicks in, which bubbled down from const proof = writeJson(SignatureProofList, attestation.proof);
.
I've no idea how to replicate this as the tests are ran against node.js
environment, but might look into getting this replicated to begin with outside of the current framework (i.e. nextjs
)
As a final note on my side, this only happens with SignatureProofList
. When running const JSONParams = writeJson(SystemParametersList, attestation.params);
I've got no errors.
Figured it out after 2 hours. Since this error only happens during production, I figured to diff the outputs from the sourced-maps enabled versions. Turns out that the minifier would mess enough of the class names for the types to not be parsed during the writeJSON
. For whoever might see this in the future, this is the line that helped me in my next.config.js
although likely would be needed in similar webpack-bundling setups:
webpack: (config) => {
config.optimization.minimize = false;
return config;
},