@google-cloud/pubsub version: 0.28.11.
export PUBSUB_EMULATOR_HOST="..."
export GOOGLE_CLOUD_PROJECT="..."
2.
const {PubSub} = require('@google-cloud/pubsub')
const pubsub = new PubSub()
const [topics] = await pubsub.getTopics()
List of topics for the project specified in the environment variable for the local emulated Pub/Sub.
node_modules/@google-cloud/projectify/build/src/index.js:45
throw new MissingProjectIdError();
^
Error: Sorry, we cannot connect to Cloud Services without a project
ID. You may specify one with an environment variable named
"GOOGLE_CLOUD_PROJECT".
at replaceProjectIdToken (node_modules/@google-cloud/projectify/build/src/index.js:45:19)
at Object.replaceProjectIdToken (node_modules/@google-cloud/projectify/build/src/index.js:38:30)
at getClient_ (node_modules/@google-cloud/pubsub/build/src/pubsub.js:644:36)
at PubSub.getClient_ (node_modules/@google-cloud/pubsub/build/src/pubsub.js:623:9)
at PubSub.request (node_modules/@google-cloud/pubsub/build/src/pubsub.js:638:14)
at PubSub.getTopics [as getTopics_] (node_modules/@google-cloud/pubsub/build/src/pubsub.js:567:14)
at makeRequest (node_modules/@google-cloud/paginator/build/src/index.js:240:13)
at Object.makeRequest (node_modules/@google-cloud/paginator/build/src/index.js:52:27)
at Transform.stream.once (node_modules/@google-cloud/paginator/build/src/index.js:237:21)
at Object.onceWrapper (events.js:277:13)
Project ID is not read from the environment variables if the emulator mode is on:
https://github.com/googleapis/nodejs-pubsub/blob/3388fb735b87a8ac817c604cf777a5d8d4e7f833/src/pubsub.ts#L818)
Therefore, it stays equal to placeholder ({{projectId}}) and trouble happens here:
https://github.com/googleapis/nodejs-pubsub/blob/3388fb735b87a8ac817c604cf777a5d8d4e7f833/src/pubsub.ts#L858
What is the solution to this? I am having the same problem
Can you set an explicit projectId?
new PubSub({ projectId: process.env.GOOGLE_CLOUD_PROJECT }) is an obvious workaround.
Still, would be nice to fix the bug. For example, I wanted to use /samples as a quick CLI tool to publish some messages into my local PubSub. Couldn't do it without first modifying the code.
@osrecki Thanks for the work around. I didn't think that was necessary, I am new to pub/sub
new PubSub({ projectId: process.env.GOOGLE_CLOUD_PROJECT })is an obvious workaround.Still, would be nice to fix the bug. For example, I wanted to use /samples as a quick CLI tool to publish some messages into my local PubSub. Couldn't do it without first modifying the code.
does this work?
I'm still getting
{ Error: Sorry, we cannot connect to Cloud Services without a project
ID. You may specify one with an environment variable named
"GOOGLE_CLOUD_PROJECT"}
With this workaround
@osrecki I'm going ahead and closing this issue, since it sounds like you're unblocked.
I've gone ahead and opened this issue, since it does sound like this is a confusing sharp corner on the library.
@guyiluz my guess is that GOOGLE_CLOUD_PROJECT might not be populated in your case, try adding console.info(process.env.GOOGLE_CLOUD_PROJECT) just before executing your library.
If you're continuing to bump into problems, please go ahead and open a new issue with a reproduction.
Most helpful comment
new PubSub({ projectId: process.env.GOOGLE_CLOUD_PROJECT })is an obvious workaround.Still, would be nice to fix the bug. For example, I wanted to use /samples as a quick CLI tool to publish some messages into my local PubSub. Couldn't do it without first modifying the code.