TypeError: Channel credentials must be a ChannelCredentials object when creating CloudTasksClient
vrayco opened this issue · comments
I'm encountering the same problem as detailed in this GitHub issue: #77. Despite attempting the suggested workaround of aligning the @grpc/grpc-js version, the issue persists.
The error message I'm receiving is:
TypeError: Channel credentials must be a ChannelCredentials object at new ChannelImplementation
This error arises when executing the following code:
const client = new CloudTasksClient({
port: 8123,
servicePath: "localhost",
sslCreds: credentials.createInsecure(),
});
The versions I'm using are:
- Npm dependency: @google-cloud/tasks: 4.0.1
- Docker image: cloud-tasks-emulator: 1.2.0
@vrayco I came across the same error
TypeError: Channel credentials must be a ChannelCredentials object
at new ChannelImplementation (node_modules\google-gax\node_modules\@grpc\grpc-js\build\src\channel.js:29:19)
at new Client (node_modules\google-gax\node_modules\@grpc\grpc-js\build\src\client.js:65:36)
at new ServiceClientImpl (node_modules\google-gax\node_modules\@grpc\grpc-js\build\src\make-client.js:58:5)
at GrpcClient.createStub (node_modules\google-gax\build\src\grpc.js:345:22)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
The root cause is that in node_modules\google-gax\node_modules\@grpc\grpc-js\build\src\channel.js:29:19
the credentials object is checked to be an instance of google-gax/ChannelCredentials
However, in the README of this repository, the @grpc/grpc-js
library is used to create the CredentialsObject.
import { credentials } from '@grpc/grpc-js';
const client = new CloudTasksClient({
port: 8123,
servicePath: 'localhost',
sslCreds: credentials.createInsecure(),
});
Thus, the check in node_modules\google-gax\node_modules\@grpc\grpc-js\build\src\channel.js:29:19
fails because the given credentials object has a different prototype hierarchy.
I fixed it by using ChannelCredentials
from google-gax
module. No need to install or pin any dependency versions.
import { ChannelCredentials } from 'google-gax';
const client = new CloudTasksClient({
port: 8123,
servicePath: 'localhost',
sslCreds: ChannelCredentials.createInsecure(),
});
I am using "@google-cloud/tasks": "^5.0.0"
Here's a PR that updates the README #96
@stfsy It compiles but i still get build error Error: Dynamic require of "@grpc/grpc-js" is not supported
UPDATE: new version of cloud tasks available "@google-cloud/tasks": "^5.1.0", works after update