question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] `fs` patch doesn't handle `{ bigint: true }`

See original GitHub issue
  • I’d be willing to implement a fix

Describe the bug

When running on Node 15.4.0, the following error can occur:

node:fs:1931
      const dev = BigIntPrototypeToString(stats.dev, 32);
                  ^

TypeError: BigInt.prototype.toString requires that 'this' be a BigInt
    at Number.toString (<anonymous>)
    at gotStat (node:fs:1931:19)

This started happening because of this commit: https://github.com/nodejs/node/blob/8d6c2f2ada79e52ec0b376769a7d94814945bd4f/lib/fs.js#L1931

The root cause is that the fake fs implementation doesn’t correctly handle the { bigint: true } option that the various fs.stat functions can take:

https://nodejs.org/api/fs.html#fs_class_fs_stats

To Reproduce

$ nvm install 15.4.0
$ yarn init -2

update package.json to:
{
  "name": "bug",
  "scripts": {
    "start": "echo test",
    "bug": "yarn bug"
  }
}

$ yarn
$ yarn bug

➜ yarn bug
node:fs:1931
      const dev = BigIntPrototypeToString(stats.dev, 32);
                  ^

TypeError: BigInt.prototype.toString requires that 'this' be a BigInt
    at Number.toString (<anonymous>)
    at gotStat (node:fs:1931:19)
    at /private/var/folders/j7/mjhkhz7x15z0nmt42b5k2x980000gn/T/tmp.K9NgZraS/.pnp.js:4516:13

Screenshots

If applicable, add screenshots to help explain your problem.

Environment if relevant (please complete the following information):

  • OS: OSX
  • Node version 15.4.0
  • Yarn version 2.4.0

Additional context

https://discord.com/channels/226791405589233664/226793713722982400/786920513238073395

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:14
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
andreialecucommented, Dec 29, 2020

I can confirm that #2262 fixes it. It can be used via:

yarn set version from sources --branch 2262

Make sure to run yarn install afterwards.

4reactions
mfrederiksencommented, Apr 9, 2021

Any chance of this getting ported into the 2.4 branch or will it only ship in 3.0?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top 10 Most Common Node.js Developer Mistakes - Toptal
Mistake #6: Throwing Errors from Inside Callbacks. JavaScript has the notion of exceptions. Mimicking the syntax of almost all traditional languages with ...
Read more >
How do I resolve "Cannot find module" error using Node.js?
Using npm install installs the module into the current directory only (in a subdirectory called node_modules ). Is app.js located under ...
Read more >
File system | Node.js v19.3.0 Documentation
When operating on file handles, the mode cannot be changed from what it was set to with ... bigint <boolean> Whether the numeric...
Read more >
BigInt: Arbitrary precision integers in JavaScript
Number must be used. The BigInt can however be concatenated with a String . For this reason, it is recommended to continue using...
Read more >
BigInt - JavaScript - MDN Web Docs
BigInt values are similar to Number values in some ways, but also differ in a few key matters: A BigInt value cannot be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found