oven-sh / bun

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

Support import mod = require() in runtime #12812

Open huseeiin opened 4 months ago

huseeiin commented 4 months 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 4 months 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

ok i found a reproduction. its when you use jsx (1.1.30-canary.5+c608a724a)

import process = require("node:process");

function jsx() {
    return <h1>Hello</h1>;
}

console.log(process.platform);