Skip to content

Single file executable import failing for "google-gax" #19908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Flux159 opened this issue May 26, 2025 · 1 comment
Open

Single file executable import failing for "google-gax" #19908

Flux159 opened this issue May 26, 2025 · 1 comment
Labels
bug Something isn't working single-file-executable bun build --compile

Comments

@Flux159
Copy link

Flux159 commented May 26, 2025

What version of Bun is running?

1.2.10

What platform is your computer?

Darwin 24.5.0 arm64 arm

What steps can reproduce the bug?

I'm trying to get the spanner client @google-cloud/spanner working with a single file executable. Example code is here:

spannertest.ts:

import { Spanner } from "@google-cloud/spanner";

// Code getting projectId, instanceId, databaseId from env vars

const spanner = new Spanner({ projectId });
const instance = spanner.instance(instanceId);
const database = instance.database(databaseId);

const query = {
  sql: "SELECT 1",
};

const [rows] = await database.run(query);
console.log(`Query: ${rows.length} found.`);
rows.forEach((row) => console.log(row));

Building works fine after applying a patch for protobufjs:

./patches/@protobufjs%[email protected]:

diff --git a/index.js b/index.js
index 33778b5539b7fcd7a1e99474a4ecb1745fdfe508..2bbe4cab025553db0814aba2a333d615e9d335e8 100644
--- a/index.js
+++ b/index.js
@@ -9,9 +9,12 @@ module.exports = inquire;
  */
 function inquire(moduleName) {
     try {
-        var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
+        var mod = require(moduleName);
         if (mod && (mod.length || Object.keys(mod).length))
             return mod;
+        // var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
+        // if (mod && (mod.length || Object.keys(mod).length))
+        //     return mod;
     } catch (e) {} // eslint-disable-line no-empty
     return null;
 }
bun build ./spannertest.ts --compile --outfile dist/new

Running ./dist/new works fine when run from the project directory (because node_modules is still in a parent folder & has google-gax inside of it). When I move new to a new directory, I get this error:

$ ./new 
error: Cannot find package 'google-gax' from '/$bunfs/root/new'

What is the expected behavior?

google-gax should be bundled inside of a single file executable. It doesn't seem like it's dynamically imported from @google-cloud/spanner, so unclear why it's not being included as it's a nested dependency.

What do you see instead?

After moving the binary to a new dir w/out node_modules in a parent dir:

error: Cannot find package 'google-gax' from '/$bunfs/root/new'

Additional information

I was wondering two things:

  • Is it possible to debug the bunfs filesystem in a single-file-executable? Not the embeddedFiles which I know there exists a helper for, the entire file system & see why google-gax is not included.
  • How can I fix this error? I tried directly importing google-gax import * as _ggax from "google-gax"; and that doesn't work. I can build ./dist/new then move it, then do a bun install google-gax in the new directory and that works, but that defeats the purpose of a single file executable.
@Flux159 Flux159 added bug Something isn't working needs triage labels May 26, 2025
@github-actions github-actions bot added single-file-executable bun build --compile and removed needs triage labels May 26, 2025
@Flux159
Copy link
Author

Flux159 commented May 26, 2025

Some additional info thanks to googleapis/nodejs-spanner#2137 - nodejs-spanner does have dynamic loading, specifically this code around gaxProtoPath is being used to load protobufs from @grpc/proto-loader:
https://github.com/googleapis/nodejs-spanner/blob/1f06871f7aca386756e8691013602b069697bb87/src/common-grpc/service.ts#L46 and https://github.com/googleapis/nodejs-spanner/blob/1f06871f7aca386756e8691013602b069697bb87/src/common-grpc/service.ts#L1035

Will debug some more if a patch can fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working single-file-executable bun build --compile
Projects
None yet
Development

No branches or pull requests

1 participant