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

  • 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

About this issue

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

Commits related to this issue

Most upvoted comments

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.

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

Is there by any chance an up-to-date branch?

Since it has been merged master would be the most up to date

yarn set version from sources

Same problem with yarn 2.4.0 (zero install) and ts-node-dev.

$ cat ./file-system.ts
console.log("123");

~/projects/ts-data-analysis-with-zero-install/examples on  main! ⌚ 1:26:29
$ yarn ts-node ./file-system.ts
123

~/projects/ts-data-analysis-with-zero-install/examples on  main! ⌚ 1:26:53
$ yarn ts-node-dev ./file-system.ts
[INFO] 01:27:04 ts-node-dev ver. 1.1.1 (using ts-node ver. 9.1.1, typescript ver. 4.1.3)
TypeError: BigInt.prototype.toString requires that 'this' be a BigInt
    at Number.toString (<anonymous>)
    at gotStat (node:fs:1931:19)
    at /Users/darya/projects/ts-data-analysis-with-zero-install/.pnp.js:7049:13

Environment:

$ node -v && npm -v
v15.4.0
7.0.15

OS: OSX

Code: https://github.com/avevlad/ts-data-analysis-with-zero-install/tree/39223a836097ded6201592364b925798c0fddea5

The 2.4.1 only includes a TS compat fix. It’ll be part of the 3.0, which takes a bit of time due to me being on vacation at the moment - will release when I’m back.

@arcanis Odd, I’m still getting this issue with the latest yarn (2.4.1), even though it’s been released only few weeks ago, and the PR was merged in December. Maybe the relevant packages weren’t upgraded in the release?