I am trying to integrate an existing library in my new codebase using typescript
and Bun
. i am facing an issue where this library is requiring modules in code asynchronously, like follows :
let target = require(AppRoot + targetName);
target.execute(targetTask);
so passing in the targetName
, it can require the module which is a default exported object (usually an instantiated class). This was working fine when i was using this library in JS but when switching to Typescript
the target
became an Object with default being the actual instantiated class :
// in Javascript
Target {
execute : [Function]
}
// in Typescript
Target {
default : {
execute : [Funtion]
}
}
This change breaks the entire library of course as it relies on reading files that way. I am not suer if this is a Bun
or Typescript
issue, but is there a way to bypass forcing the default
when importing for a specific library
Note: I already have esModuleInterop
set to true in my tsconfig
which according to chatgpt is the only hand-off solution
I am trying to integrate an existing library in my new codebase using typescript
and Bun
. i am facing an issue where this library is requiring modules in code asynchronously, like follows :
let target = require(AppRoot + targetName);
target.execute(targetTask);
so passing in the targetName
, it can require the module which is a default exported object (usually an instantiated class). This was working fine when i was using this library in JS but when switching to Typescript
the target
became an Object with default being the actual instantiated class :
// in Javascript
Target {
execute : [Function]
}
// in Typescript
Target {
default : {
execute : [Funtion]
}
}
This change breaks the entire library of course as it relies on reading files that way. I am not suer if this is a Bun
or Typescript
issue, but is there a way to bypass forcing the default
when importing for a specific library
Note: I already have esModuleInterop
set to true in my tsconfig
which according to chatgpt is the only hand-off solution
1 Answer
Reset to default 0If you are using Bun just do
bun build --target=node file.js --outfile.js
Or, if you want, --target=bun
.
Or, just execute the TypeScript .ts
file directly with bun file.ts
.
Done.
No tsconfig.json
necessary because Bun doesn't parse Microsoft TypeScript with tsc
.