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

3.6.7: Fix for "Do not know how to serialize a BigInt" #1918

Open
JoakimCh opened this issue May 23, 2021 · 5 comments
Open

3.6.7: Fix for "Do not know how to serialize a BigInt" #1918

JoakimCh opened this issue May 23, 2021 · 5 comments

Comments

@JoakimCh
Copy link

When I'm using BigInts in my code I get this error message Do not know how to serialize a BigInt.

I know how to fix this problem, but do not ask me to create a pull request (since I do not have any knowledge of how to do that or any interest).

To fix it replace line 142 in the file lib/jsdoc/util/dumper.js with:

result.push( JSON.stringify(walker.walk(arg), (key, value) => typeof value == 'bigint' ? value.toString() : value, 4) );
@sg-p4x347
Copy link

I have also run into this issue

@kongnet
Copy link

kongnet commented Apr 20, 2022

JSDoc 3.6.10

  1. Open /node_modules/jsdoc/lib/jsdoc/src/astnode.js
  2. Add function
function strReplacer (k, v) {
  if (typeof v === 'bigint') {
    return v.toString() + 'n'
  }
  return v
}
  1. Replace all JSON.stringify(tempObject) to JSON.stringify(tempObject, strReplacer)

@datdinhquoc
Copy link

should jsdoc add that by default? manually editing a lib isn't quite right

@aikawayataro
Copy link

Alternative solution without source patching: use .js config with this code:

// BigInt JSON serialization.
BigInt.prototype.toJSON = function() {
	return this.toString() + 'n';
}

Still monkey patch too 😅 .

@mahnunchik

This comment was marked as off-topic.

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

7 participants
@mahnunchik @kongnet @JoakimCh @sg-p4x347 @datdinhquoc @aikawayataro and others