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| #5997

Closed
christoph88 opened this issue Sep 24, 2023 · 6 comments
Closed

Cannot call a class constructor without |new| #5997

christoph88 opened this issue Sep 24, 2023 · 6 comments
Labels
bug Something isn't working node.js Compatibility with Node.js APIs

Comments

@christoph88
Copy link

What version of Bun is running?

1.0.3+25e69c71e70ac8a0a88f9cf15b4057bd7b2a633a

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

Run bun initand add following code to index.ts.

const { input } = require("@inquirer/prompts");

const ask = async () => {
  const answer = await input({ message: "Enter your name" });
  console.log(answer);
  return answer;
};

ask();

Run bun install @inquirer/prompts then run ```bun run index.ts````

You will get this error. It works when setting up the project as a node app

❯ bun run index.ts 
? Enter your name
120 | 
121 | class AsyncResource {
122 |   type;
123 |   #snapshot;
124 | 
125 |   constructor(type, options) {
                             ^
TypeError: Cannot call a class constructor without |new|
      at AsyncResource (node:async_hooks:125:26)
      at run (/Users/christoph/Code/testing/inquirer/node_modules/@inquirer/core/dist/cjs/lib/hook-engine.js:96:13)
      at workLoop (/Users/christoph/Code/testing/inquirer/node_modules/@inquirer/core/dist/cjs/lib/create-prompt.js:114:24)

      at /Users/christoph/Code/testing/inquirer/node_modules/@inquirer/core/dist/cjs/lib/create-prompt.js:123:20
      at processTicksAndRejections (:55:76)

What is the expected behavior?

Open a cli prompt and enable input

What do you see instead?

❯ bun run index.ts 
? Enter your name
120 | 
121 | class AsyncResource {
122 |   type;
123 |   #snapshot;
124 | 
125 |   constructor(type, options) {
                             ^
TypeError: Cannot call a class constructor without |new|
      at AsyncResource (node:async_hooks:125:26)
      at run (/Users/christoph/Code/testing/inquirer/node_modules/@inquirer/core/dist/cjs/lib/hook-engine.js:96:13)
      at workLoop (/Users/christoph/Code/testing/inquirer/node_modules/@inquirer/core/dist/cjs/lib/create-prompt.js:114:24)

      at /Users/christoph/Code/testing/inquirer/node_modules/@inquirer/core/dist/cjs/lib/create-prompt.js:123:20
      at processTicksAndRejections (:55:76)

Additional information

No response

@christoph88 christoph88 added the bug Something isn't working label Sep 24, 2023
@Electroid Electroid added the node.js Compatibility with Node.js APIs label Sep 24, 2023
@jimmywarting
Copy link

jimmywarting commented Sep 24, 2023

eh... had a look at what @inquirer/core is doing with withUpdates
what they are doing looks wrong...?

AsyncResource is a class and they should treat it as such...? not by binding it to a new function.
i think they should actually do something like:

class Wrapped extends AsyncResource {
  constructor(...args) { ... }
}

// and then call it as such:
new Wrapped(...)

Feels like a @inquirer/core bug to me...

EDIT: i saw that AsyncResource.bind was a thing apparently... however it's deprecated and should not be used anymore.

@christoph88
Copy link
Author

@jimmywarting thanks I'll pass it on

@bompi88
Copy link

bompi88 commented Sep 25, 2023

Any workaround for this atm?

@Jarred-Sumner
Copy link
Collaborator

Fixed by @paperdave in #6095

@iway1
Copy link

iway1 commented May 5, 2024

still having this issue

EDIT: nvm hadn't upgraded bun since before #6095

@dante4rt
Copy link

Still having this issue too..

120 | 
121 | class AsyncResource {
122 |   type;
123 |   #snapshot;
124 | 
125 |   constructor(type, options) {
                             ^
TypeError: Cannot call a class constructor without |new|
      at AsyncResource (node:async_hooks:125:26)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node.js Compatibility with Node.js APIs
Projects
None yet
Development

No branches or pull requests

7 participants