oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.26k stars 2.69k forks source link

Support import mod = require() in runtime #12812

Open huseeiin opened 1 month ago

huseeiin commented 1 month ago

What is the problem this feature would solve?

currently, bun supports import fs = require("node:fs"); (it transpiles to import.meta.require) in bun build but not in runtime.

What is the feature you are proposing to solve the problem?

this should be a part of typescript support

What alternatives have you considered?

No response

huseeiin commented 1 month ago

After invesitgating, bun does support this feature. but i'm getting

1 | import Router = require("./router");
                  ^
error: Expected "from" but found "="
    at input.jsx:1:15

Bun v1.1.20 (Linux x64)

and i couldn't make a minimal reproduction also, my file name is not "input.jsx" this is a weird error

huseeiin commented 1 month ago

i created a non-minimal reproduction: https://github.com/huseeiin/bun-ts-require-bug