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

Created on 11 Dec 2020  Â·  5Comments  Â·  Source: yarnpkg/berry

  • [x] 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

bug upholded

All 5 comments

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

I started making a branch that implements that option in the FakeFS interfaces and up through all the implementers, but if y'all are working on it already you can probably do it a lot faster than I can as an outsider.

I have a pull request open for @types/node to fix definitions for stat/lstat/fstat in callback, synchronous, promisify, and promises mode. I don't think you can successfully write a shim for fs if the definitions aren't right, and I don't think the definitions are right in the @types/node package. (For example, they have an fstat in fs.promises, and that doesn't appear to exist.)

I have the same issue with yarn 2.4.0 and node 15.4.0, but not with previous versions of node

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

juanpicado picture juanpicado  Â·  4Comments

benwainwright picture benwainwright  Â·  3Comments

Santas picture Santas  Â·  3Comments

milichev picture milichev  Â·  3Comments

dzintars picture dzintars  Â·  3Comments