admin管理员组文章数量:1360003
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
.
版权声明:本文标题:javascript - running js libraries that use require in typescript + bunJS forces the use of .default - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743914535a2560986.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论