Skip to content

CreateUserAgentString() method crashes application when running from a single executable produced by Bun #30

@Seagull29

Description

@Seagull29

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');
located within the CreateUserAgentString() method, throws the following error when running the application:

Image

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:

Image

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');

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 💔

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions