oven-sh/bun

`cpy` library fails with "undefined is not an object" error (probably related to node:streams and p-event)

Open

#5,560 opened on 2023年9月16日

GitHub で見る
 (6 comments) (0 reactions) (1 assignee)Rust (90,348 stars) (4,486 forks)batch import
buggood first issuenode.js

説明

What version of Bun is running?

1.0.2+37edd5a6e389265738e89265bcbdf2999cb81a49

What platform is your computer?

Darwin 19.6.0 x86_64 i386

What steps can reproduce the bug?

Make a new bun proj in a test directory. And make sure the cpy library is installed:

bun init
bun i cpy

Make a file called dir1/a.txt:

aaaa

Another file called index.ts:

import cpy from 'cpy';

try {
    await cpy('./dir1/**', './dir2');
} catch (err) {
    console.log((err as Error).stack);
    throw err;
}

Then run it:

bun index.ts 

What is the expected behavior?

Copy of dir1/a.txt to dir2/a.txt. This is what node does.

What do you see instead?

Error: Cannot read from `/Users/ryan/crap/issue-reports/bun/cpy1/dir1/a.txt`: undefined is not an object
    at <anonymous> (/Users/ryan/crap/issue-reports/bun/cpy1/node_modules/cp-file/fs.js:20:81)
    at asyncFunctionResume (native)
    at promiseReactionJobWithoutPromiseUnwrapAsyncContext (native)
    at promiseReactionJob (native)
    at processTicksAndRejections (native)
Caused By: TypeError: undefined is not an object
    at <anonymous> (node:stream:1743:162)
    at <anonymous> (/Users/ryan/crap/issue-reports/bun/cpy1/node_modules/p-event/index.js:71:13)
    at new Promise (:1:11)
    at pEventMultiple (/Users/ryan/crap/issue-reports/bun/cpy1/node_modules/p-event/index.js:19:12)
    at pEvent (/Users/ryan/crap/issue-reports/bun/cpy1/node_modules/p-event/index.js:104:18)
    at <anonymous> (/Users/ryan/crap/issue-reports/bun/cpy1/node_modules/cp-file/fs.js:19:10)
    at createReadStream (/Users/ryan/crap/issue-reports/bun/cpy1/node_modules/cp-file/fs.js:15:34)
    at <anonymous> (/Users/ryan/crap/issue-reports/bun/cpy1/node_modules/cp-file/index.js:11:66)
    at processTicksAndRejections (:55:39)
CpyError: Cannot copy from `dir1/a.txt` to `dir2/a.txt`: Cannot read from `/Users/ryan/crap/issue-reports/bun/cpy1/dir1/a.txt`: undefined is not an object

Additional information

It seems the error is more related to a p-event library call. But going through cpy seems to be the easiest way to show it off with a small amount of code.

The problem could be because I'm on Catalina (10.15), which is a fairly old version of osx.

コントリビューターガイド