-
Notifications
You must be signed in to change notification settings - Fork 598
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
Webpack and other bundler support #2933
Comments
There are short-term and long-term plans for this. The short-term solution is to make The long-term solution is to use grpc-web library, which (unfortunately) is not compatible to |
We've been able to support Webpack builds of google cloud libraries in ncc through the use of static analysis in our asset relocation loader (https://github.com/zeit/webpack-asset-relocator-loader), which should support both client and server use cases. We've been fixing bugs as we find them on the grpc libraries, and need to support this anyway. If it would be useful to provide some examples of browser workflows with this approach we could gladly assist with this. |
@guybedford 👋 would love to work with you to start adding some web examples over time. |
@bcoe more than happy to share how we achieved this with ncc, and possibly even make our approach available to other webpack users, but it does involve an asset analysis running against all source code to determine the ".proto" references. Having a fallback JSON-loading / browser bundling approach seems to make sense though architecturally for this project. Perhaps a simple |
@alexander-fenster is there a thread you can link to here that demonstrates how to use the grpc-fallback, I know you documented this in another thread. |
@bcoe For using it with Node.js and service account, just pass const fooClient = new client.FooClient({fallback: true}); To use in non-Node setting, one cannot use service account and will need to use OAuth2 workflow. It can be done using the following code. It really depends on how your application works (if it's a website, or an Electron app, or something else), so I'm just showing the general idea of performing the OAuth2 workflow leaving the specifics behind (e.g. how to redirect the user to auth URI, how to extract the auth code from the query string, etc.) The parameters const client = require('@google-cloud/foo'); // any GAPIC library
const auth = require('google-auth-library');
const oauth2client = new auth.OAuth2Client(client_id, client_secret, callback_uri);
const authUrl = oauth2client.generateAuthUrl({
access_type: 'offline',
scope: client.FooClient.scopes
});
// redirect user to authUrl and wait for them coming back to callback_uri
// in callback_uri handler, get the auth code from query string and obtain a token:
const tokenResponse = await oauth2client.getToken(code);
oauth2client.setCredentials(tokenResponse.tokens);
// now use this oauth2client!
const fooClient = new client.FooClient({ auth: oauth2client }); // <-- auth passed here If the library detects it's running in a browser (has a |
I am very new to development, so please forgive me if I'm overlooking the answer to this...
This, of course, isn't going to work for the web application, because it needs to pull data from the Drive every time the site is visited. |
Hi @ddittoPersevere, thank you for asking! It's possible to use the Drive library in your web application if you prepare a separate Webpack bundle by following these steps. Please let us know if anything is unclear! |
@en4letto If you pass |
@alexander-fenster thanks for the insight! I did some additional checks, here's what I found:
I've added some logs and the code correctly assigns the I found an issue about WIth this edit the code works perfectly! Do you happen to have some suggestions on how to possibly apply this fix when bundling the code with Thanks again! |
Thank you for these details! I will test if adding Having said that - @en4letto can you tell us more about the environment you're running your code in? If this is an express app that runs with Node, why do you need to webpack it? Fallback mode was initially supposed to help run the code in browsers (where gRPC is not available), so I just want to understand your use case and maybe make some recommendations. |
@alexander-fenster I am setting up a production environment in GCP. I'm using the managed instance groups, and I wanted the lowest startup time possible for the instances inside the node group. Hope this is clear! If you have some recommendations and suggestions I'll be happy to know them, as Node.js is not my specialty :) |
Hey @alexander-fenster @en4letto, is there an issue which I can follow for the google-gax node-fetch thing? Had no luck finding the right one. Trying to use the Thanks in advance :) |
@alexander-fenster confirming that I run across this |
I was generally able to workaround webpack issues using |
The fix is coming to all the libraries that will stop using |
Any updates on this? I need to use |
@s-dschro any update on what exactly? :) This issue is a collection of various problems related to webpack and/or other bundlers. What is the exact error you have with |
Thanks @s-dschro, I'll try to route that issue as appropriate. |
@alexander-fenster When trying the non-Node sample provided within a React app, I get this error message:
Any ideas what could be causing this? |
@JJPell |
Hi I'm trying to use this package or https://github.com/google/google-api-javascript-client for using google tag manager on react-native, react-native has fetch and no window object, anyone has a working build configuration for it? |
Hi I'm trying to use google cloud secret manager but this error keeps showing up whenever I try to import the SecretManagerServiceClient I tried following the documentation here but still can't make it run I also tried adding There are multiple errors that are similar to this error message so I didn't copy them but essentially all error are coming from tunnel-agent
sample code
btw I am using angular 14.2.12 and using google cloud secret manager version 5.2.0 Any help would be much appreciated thank you. |
Seems like a lot of users want to use webpack with a number of the nodejs client libraries.
Threads where this comes up:
Threads demonstrating use of fallback
true
:The text was updated successfully, but these errors were encountered: