@google-cloud/pubsub version: "^0.28.1"try {
data = 'my_Data'
const pubsub = new PubSub({
projectId: config.gcloudProjectID,
keyFilename: './pubSubKey.json',
});
const payload = JSON.stringify({ someData: data });
const dataBuffer = Buffer.from(payload);
const messageId = await pubsub.topic(config.topicName).publish(dataBuffer);
} catch (err) {
logError('Failed to publish pubsub with error: ', err);
throw err;
}
I used a similar setup as above in another project and it worked fine.
Error: not supported
at GoogleProtoFilesRoot.loadSync (/Users/dev/tool/node_modules/protobufjs/src/root.js:234:15)
at Object.loadSync (/Users/dev/tool/node_modules/protobufjs/src/index-light.js:69:17)
at GrpcClient.loadProtoLegacy (/Users/dev/tool/node_modules/google-gax/build/src/grpc.js:164:54)
at GrpcClient.loadProto (/Users/dev/tool/node_modules/google-gax/build/src/grpc.js:200:42)
at new PublisherClient (/Users/dev/tool/node_modules/@google-cloud/pubsub/build/src/v1/publisher_client.js:95:15)
at PubSub.getClient_ (/Users/dev/tool/node_modules/@google-cloud/pubsub/build/src/pubsub.js:620:25)
at PubSub.request (/Users/dev/tool/node_modules/@google-cloud/pubsub/build/src/pubsub.js:638:14)
at Publisher.publish_ (/Users/dev/tool/node_modules/@google-cloud/pubsub/build/src/publisher.js:141:20)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10) +0ms
Looks like a gRPC issue. Could you try reinstalling your node modules and deleting any package locks you may have?
Hey @callmehiphop
Thank you for the quick reply.
I deleted both node modules and package-lock.json then ran npm install. However, unfortunately it didn't resolve the issue, it's still throwing the same error and is unable to publish
@callmehiphop Can you provide another further steps regarding this issue. Unfortunately we are still blocked due to this error.
@Msarnaot so I took a closer look at the error in question. Looks like protobuf is trying to figure out whether or not the current environment is Node or not, I guess my follow up questions would be
@callmehiphop I'm running this on a server where we are doing server side rendering. So the project technically has both react and node code, however we are only using the library in the server portion.
In this
util.global = typeof window !== "undefined" && window
|| typeof global !== "undefined" && global
|| typeof self !== "undefined" && self
|| this; // eslint-disable-line no-invalid-this
util.global is being set to window and not global in our project. Which doesn't have .process. However, in another project we have, which is a pure Nodejs server, it resolves util.global to global. What do you recommend in this scenario?
The behavior would be different if the code was changed to priorities global over window in the definition, like so:
util.global = typeof global !== "undefined" && global
|| typeof window !== "undefined" && window
|| typeof self !== "undefined" && self
|| this; // eslint-disable-line no-invalid-this
As global is defined in our case.
@callmehiphop
We were able to resolve this issue. Since we did server side rendering we had some of our node intertwined with libraries that set the "window" variable and stored data in it. By the time we required the google-cloud pubsub library, the window was set and util.isNode resolves to false. We moved the require that included our pubsub code to run before any libraries that set the window object, and this resolved the issue for us a s util.isNode is true by the time it runs.
@Msarnaot thanks for the update, glad to hear you found a work around!
@callmehiphop
We were able to resolve this issue. Since we did server side rendering we had some of our node intertwined with libraries that set the "window" variable and stored data in it. By the time we required the google-cloud pubsub library, the window was set and util.isNode resolves to false. We moved the require that included our pubsub code to run before any libraries that set the window object, and this resolved the issue for us a s util.isNode is true by the time it runs.
Can you help me I am doing server side rendering angular universal
To remove window not found i did this
const template = fs.readFileSync(path.join( '.', 'dist/browser', 'index.html')).toString();
const win = domino.createWindow(template);
global['window'] = win;
global['document'] = win.document
global['DOMTokenList'] = win.DOMTokenList;
global['Node'] = win.Node;
global['Text'] = win.Text;
global['HTMLElement'] = win.HTMLElement;
global['navigator'] = win.navigator;
Now i am getting same error as you on running npm run serve:ssr

Greetings! Can you open a new issue?
Getting the same error as @hbk899
@danieldanielecki I would suggest opening an issue in the protobuf package.
@hbk899 @danieldanielecki you can fix by adding process to your fake window in the server.ts file
win.process = process;
You can find more info in this article, with also other errors I encountered with Angular SSR + Firebase
@callmehiphop
We were able to resolve this issue. Since we did server side rendering we had some of our node intertwined with libraries that set the "window" variable and stored data in it. By the time we required the google-cloud pubsub library, the window was set and util.isNode resolves to false. We moved the require that included our pubsub code to run before any libraries that set the window object, and this resolved the issue for us a s util.isNode is true by the time it runs.
maza aa gya bhai
love you
Most helpful comment
@callmehiphop
We were able to resolve this issue. Since we did server side rendering we had some of our node intertwined with libraries that set the "window" variable and stored data in it. By the time we required the google-cloud pubsub library, the window was set and util.isNode resolves to false. We moved the require that included our pubsub code to run before any libraries that set the window object, and this resolved the issue for us a s util.isNode is true by the time it runs.