Unable to use with TypeScript
Hi,
The module is great! But I can't use it with a TypeScript Lambda function on AWS. It fails in runtime with error:
TypeError: Right-hand side of 'instanceof' is not callable
at str (***:/node_modules/json-bigint/lib/stringify.js:218:1)
at Function.module.exports.JSON.stringify (***:/node_modules/json-bigint/lib/stringify.js:380:1)
at Response.toLambdaResponse (***:/_core/response.ts:91:71)
at LambdaHandler.execute (***:/_core/LambdaHandler.ts:123:47)
at processTicksAndRejections (internal/process/task_queues.js:94:5)
My tsconfig.json is
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": false,
"module": "commonjs",
"target": "esnext",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"declaration": false,
"listFiles": false,
"allowJs": true,
"allowSyntheticDefaultImports": true,
"lib": [
"esnext",
"es2019"
]
}
}
Thanks for report @bushev ! would you be able to make a simple repo ready to reproduce issue?
Hey Andrey,
please, check it out: https://github.com/bushev/json-bigint/tree/master/issue
hm, the problem is in a way how webpack bundles bignumber.js
If I replace first line in stringify.js to var BigNumber = require('bignumber.js').default; then your example works ( but obviously native node CJS examples don't )
Not sure yet how to solve this for both node and webpack consumers
I did a simple fix based on the details you provided. It works well for me - https://github.com/bushev/json-bigint/commit/e3e93f71d633cd558bc7c57afcd9e1f54f669d0b
Any updates on this? I'm facing with the same issue.
Another solution that works with the usage of patch-package:
$ cat patches/json-bigint+1.0.0.patch
diff --git a/node_modules/json-bigint/lib/stringify.js b/node_modules/json-bigint/lib/stringify.js
index 3bd5269..b4a3319 100644
--- a/node_modules/json-bigint/lib/stringify.js
+++ b/node_modules/json-bigint/lib/stringify.js
@@ -215,7 +215,7 @@ var JSON = module.exports;
mind = gap,
partial,
value = holder[key],
- isBigNumber = value != null && (value instanceof BigNumber || BigNumber.isBigNumber(value));
+ isBigNumber = value != null && (value instanceof BigNumber.default || BigNumber.default.isBigNumber(value));
// If the value has a toJSON method, call it to obtain a replacement value.
i have this issue too , error: BigNumber is not a constructor
Same issue.
For now you can use "@types/json-bigint": "^1.0.1" in typescript, than import { parse as jsonBigIntParse, stringify as sonBigIntStringify, } from 'json-bigint'; and its working very well.
For now you can use
"@types/json-bigint": "^1.0.1"in typescript, thanimport { parse as jsonBigIntParse, stringify as sonBigIntStringify, } from 'json-bigint';and its working very well.
Unfortunately I still get the error when using this solution in AWS Lambda
2022-05-11T07:31:09.601Z 942f9df2-3e1c-4939-9e98-d56e7e6f4b3d INFO TypeError: Right-hand side of 'instanceof' is not callable
at p (/var/task/app.js:2:823196)
at a.stringify.a.stringify (/var/task/app.js:2:824298)
at /var/task/app.js:8:10524
at Generator.next (<anonymous>)
at /var/task/app.js:8:9856
at new Promise (<anonymous>)
at i (/var/task/app.js:8:9601)
at t.matchPools (/var/task/app.js:8:10007)
at /var/task/app.js:8:9222
I did a simple fix based on the details you provided. It works well for me - bushev@e3e93f7
The fix fixed the issue. When will you update the npm version?
Good brother, when will you update the npm version?
Confirmed that https://github.com/bushev/json-bigint/commit/e3e93f71d633cd558bc7c57afcd9e1f54f669d0b fixes this issue for me.
I published a fork with the fixes: https://www.npmjs.com/package/@toniq-labs/json-bigint