oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.09k stars 2.47k forks source link

fs.promises.writeFile(fs.promises.FileHandle) ERR_INVALID_ARG_TYPE #10874

Open emmercm opened 1 week ago

emmercm commented 1 week ago

What version of Bun is running?

1.1.7+b0b7db5c0

What platform is your computer?

Darwin 23.4.0 arm64 arm

What steps can reproduce the bug?

Run this JavaScript:

import fs from 'node:fs';

(async (): Promise<void> => {
  const file = await fs.promises.open('dummy.txt', 'w');
  await fs.promises.writeFile(file, 'data');
  await file.close();
})();

What is the expected behavior?

This is valid code for writing files with Node.js, so I'm hoping it can be supported with Bun.

What do you see instead?

1 | import fs from 'node:fs';
2 | 
3 | (async (): Promise<void> => {
4 |   const file = await fs.promises.open('dummy.txt', 'w');
5 |   await fs.promises.writeFile(file, 'data');
            ^
TypeError: path must be a string or a file descriptor
 code: "ERR_INVALID_ARG_TYPE"

      at /Users/cemmer/Resilio Sync/Development/igir/dummy.ts:5:9

Bun v1.1.7 (macOS arm64)

Additional information

fs.promises.FileHandle.writeFile() appears to work fine with Bun:

import fs from 'node:fs';

(async (): Promise<void> => {
  const file = await fs.promises.open('dummy.txt', 'w');
  await file.writeFile('data');
  await file.close();
})();