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

Unable to use with TypeScript #34

Open
bushev opened this issue May 19, 2020 · 14 comments
Open

Unable to use with TypeScript #34

bushev opened this issue May 19, 2020 · 14 comments

Comments

@bushev
Copy link

bushev commented May 19, 2020

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"
    ]
  }
}
@sidorares
Copy link
Owner

Thanks for report @bushev ! would you be able to make a simple repo ready to reproduce issue?

@bushev
Copy link
Author

bushev commented May 19, 2020

Hey Andrey,

please, check it out: https://github.com/bushev/json-bigint/tree/master/issue

@sidorares
Copy link
Owner

sidorares commented May 19, 2020

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

@bushev
Copy link
Author

bushev commented May 19, 2020

I did a simple fix based on the details you provided. It works well for me - bushev@e3e93f7

@cr0cK
Copy link

cr0cK commented Apr 20, 2021

Any updates on this?
I'm facing with the same issue.

@cr0cK
Copy link

cr0cK commented Apr 20, 2021

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.

@zhfnjust
Copy link

zhfnjust commented May 5, 2021

i have this issue too , error: BigNumber is not a constructor

@ivands
Copy link

ivands commented Jun 8, 2021

Same issue.

@NetMajom
Copy link

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.

@tonisives
Copy link

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.

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

@ifgeny87
Copy link

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?

@CHENGCHANGHU
Copy link

Good brother, when will you update the npm version?

@electrovir
Copy link

Confirmed that bushev@e3e93f7 fixes this issue for me.

I published a fork with the fixes: https://www.npmjs.com/package/@toniq-labs/json-bigint

@vladaman
Copy link

I am experiencing the same issue, with Javascript, Node 22.x and Webpack in serialize method. Unfortunately the fork from @electrovir doesn't work either.

"TypeError: Right-hand side of 'instanceof' is not callable",
    "    at str (/var/task/index.js:39122:51)",

at this line:

isBigNumber = value != null && (value instanceof BigNumber || BigNumber.isBigNumber(value));

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

No branches or pull requests