Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with Node.js: Custom methods on extended Socket class not recognized #16079

Open
vikiboss opened this issue Dec 31, 2024 · 0 comments
Labels
bug Something isn't working confirmed bug We can reproduce this issue node:net

Comments

@vikiboss
Copy link

What version of Bun is running?

v1.1.42, and Node.js v22.11.0

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

  1. Create a file named main.mjs and insert the following code:
import { Socket } from 'node:net';

class Network extends Socket {
  join() {
    console.log('Joined!');
  }
}

const n = new Network();

n.on('connect', () => {
  console.log('Connected!');
  n.join();
});

n.connect(443, 'google.com');
  1. Execute the script with bun run main.mjs and node main.mjs. Observing the error thrown by bun will reveal:
Connected!
10 | 
11 | n.connect(443, 'google.com')
12 | 
13 | n.on('connect', () => {
14 |   console.log('Connected!')
15 |   n.join()
         ^
TypeError: n.join is not a function. (In 'n.join()', 'n.join' is undefined)
      at /main.mjs:15:5
      at emit (node:events:75:22)
      at open (node:net:102:63)

What is the expected behavior?

Bun is expected to exhibit behavior identical to that of Node.js, or did I miss something?

What do you see instead?

No response

Additional information

No response

@vikiboss vikiboss added bug Something isn't working needs triage labels Dec 31, 2024
@pfgithub pfgithub added node:net confirmed bug We can reproduce this issue and removed needs triage labels Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed bug We can reproduce this issue node:net
Projects
None yet
Development

No branches or pull requests

2 participants