-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Environment
-
Bun single file executable created with the following command:
RUN bun build --compile --minify --target=bun --outfile bundle ./src/index.ts
using oven/bun:1-debian docker image -
Application single file executable running on a Debian Trixie Slim container
Issue
It seems the following line
| const packageJSON = module[`require`].call(module, '../package.json'); |
I guess "module" is undefined when bundling using the Bun bundle command
Partial solution
I was able to bypass the error with the following patch:
static CreateUserAgentString() {
let productVersion = 'ProductVersion';
if (Utils_1.isNode && typeof module !== "undefined" && module.require) {
try {
// require('./package.json') hide require call from browser bundler, e.g. webpack
const packageJSON = module[`require`].call(module, '../package.json');
productVersion = packageJSON.version;
} catch (error) {
}
}
return `${CapMonsterCloudClientFactory.productName}/${productVersion}`;
}
However, as soon as the previous exception was solved, another one came up from this line of code:
| const requester = module[`require`].call(module, this.url.protocol === 'https:' ? 'https' : 'http'); |
Getting:
Unfortunately, since the createAgent() method is responsible for the http requests I guess, I didn't know how to bypass that.
Conclusion
There is even one more line of code that may throw the same kind of error located in the following line:
| createDebugger = module[`require`].call(module, 'debug'); |
| const packageJSON = module[`require`].call(module, '../package.json'); |
capmonstercloud-client-js/src/HttpClient.ts
Line 205 in 2364e72
| const requester = module[`require`].call(module, this.url.protocol === 'https:' ? 'https' : 'http'); |
| const requester = module[`require`].call(module, this.url.protocol === 'https:' ? 'https' : 'http'); |
Those are the lines I could find are likely to throw the same error when running from the single executable produced by Bun.
Please, I would be glad if you could take a look at this issue, at the moment I think they are making applications on Bun unable to run or perhaps I'm doing something wrong or I should switch back to Node 💔