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

Cannot call a class constructor without |new| #5006

Closed
endel opened this issue Sep 11, 2023 · 6 comments
Closed

Cannot call a class constructor without |new| #5006

endel opened this issue Sep 11, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@endel
Copy link

endel commented Sep 11, 2023

What version of Bun is running?

1.0.0

What platform is your computer?

Darwin 22.3.0 arm64 arm

What steps can reproduce the bug?

import http from "http";

class MyClass {
  constructor() {
    http.OutgoingMessage.call(this);
  }
}

const instance = new MyClass();
console.log(instance);

What is the expected behavior?

❯ npx tsx cannot-call-a-class-constructor.ts

MyClass {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  outputData: [],
  outputSize: 0,
  writable: true,
  destroyed: false,
  _last: false,
  chunkedEncoding: false,
  shouldKeepAlive: true,
  maxRequestsOnConnectionReached: false,
  _defaultKeepAlive: true,
  useChunkedEncodingByDefault: true,
  sendDate: false,
  _removedConnection: false,
  _removedContLen: false,
  _removedTE: false,
  strictContentLength: false,
  _contentLength: null,
  _hasBody: true,
  _trailer: '',
  finished: false,
  _headerSent: false,
  _closed: false,
  socket: null,
  _header: null,
  _keepAliveTimeout: 0,
  _onPendingData: [Function: nop],
  [Symbol(kCapture)]: false,
  [Symbol(kBytesWritten)]: 0,
  [Symbol(kNeedDrain)]: false,
  [Symbol(corked)]: 0,
  [Symbol(kOutHeaders)]: null,
  [Symbol(errored)]: null
}

What do you see instead?

❯ bun run cannot-call-a-class-constructor.ts

516 |   }
517 | }
518 |
519 | class OutgoingMessage extends Writable {
520 |
521 |   constructor() {
                             ^
TypeError: Cannot call a class constructor without |new|
      at OutgoingMessage (node:http:521:26)
      at new MyClass (/Users/endel/Projects/colyseus/bun-express/cannot-call-a-class-constructor.ts:5:4)
      at /Users/endel/Projects/colyseus/bun-express/cannot-call-a-class-constructor.ts:9:17

Additional information

This code runs correctly using npx tsx cannot-call-a-class-constructor.ts

@endel endel added the bug Something isn't working label Sep 11, 2023
@sirenkovladd
Copy link
Contributor

related to #4415

@RyanWhipple
Copy link

I believe I have the same issue using nock and axios

import axios from "axios"
import * as nock from "nock"

nock.load(filepathToPreviouslySavedNockRecording.json)

const bulbasaur = await axios({
  method: "GET",
  url: "https://pokeapi.co/api/v2/pokemon/bulbasaur"
})

I get:

519 | class OutgoingMessage extends Writable {
520 | 
521 |   constructor() {
                             ^
TypeError: Cannot call a class constructor without |new|
      at OutgoingMessage (node:http:521:26)
      at new OverriddenClientRequest (/Users/rwhipple/Documents/study-bun/node_modules/nock/lib/intercept.js:279:4)
      at /Users/rwhipple/Documents/study-bun/node_modules/nock/lib/intercept.js:427:13
      at /Users/rwhipple/Documents/study-bun/node_modules/nock/lib/common.js:96:13
      at /Users/rwhipple/Documents/study-bun/node_modules/follow-redirects/index.js:284:8
      at new RedirectableRequest (/Users/rwhipple/Documents/study-bun/node_modules/follow-redirects/index.js:66:2)
      at request (/Users/rwhipple/Documents/study-bun/node_modules/follow-redirects/index.js:523:13)
      at /Users/rwhipple/Documents/study-bun/node_modules/axios/lib/adapters/http.js:438:10
      at dispatchHttpRequest (/Users/rwhipple/Documents/study-bun/node_modules/axios/lib/adapters/http.js:149:54)
      at /Users/rwhipple/Documents/study-bun/node_modules/axios/lib/adapters/http.js:143:4

@dhrn
Copy link

dhrn commented Sep 17, 2023

+1

@karl-run
Copy link

Related to #4787, seems to be the same underlying cause.

konstfish added a commit to konstfish/bonsai that referenced this issue Nov 12, 2023
@alexmacarthur
Copy link

I'm seeing the same issue using Inquirer.js.

@gvilums
Copy link
Contributor

gvilums commented May 2, 2024

Can't repro this on 1.1.7 so I'm going to close this, if it's still relevant feel free to reopen

@gvilums gvilums closed this as completed May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants