Skip to content

Cannot call a class constructor without |new| #5997

@christoph88

Description

@christoph88

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnode.jsCompatibility with Node.js APIs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions