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):
Additional context
https://discord.com/channels/226791405589233664/226793713722982400/786920513238073395
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
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.