Joseph Lust
Joseph Lust

Reputation: 19975

GCP Secret Manager throws: "path" argument must be of type string

I'm working on using the GCP Secrets Manager from Node.js 8.x (I know, it's ancient, but it's the newest GA Node runtime on Cloud Functions). However, when I run their example, it keeps throwing gRPC error from this line:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object

Line of code I'm trying to test:

const secretClient = new SecretManagerServiceClient();

I get the same error if I'm running on Node 8.x or Node 10.x, and if I use the latest version of the secrets lib (3.0.0) or the legacy version for Node 8.x (1.2.1)

Upvotes: 2

Views: 261

Answers (1)

Joseph Lust
Joseph Lust

Reputation: 19975

It appears this error occurred because the library is running browser rather than Node mode, which forces it to avoid "fallback" mode, trying to lookup the gRPC path incorrectly. The decision is because window is in scope, tricking the isBrowser logic.

Root Cause

The root cause is that jest was used to test, which by default runs in jsDom mode, inserting globals like window.

Fix

Add the following to your jest.config.json file.

testEnvironment: 'node',

Upvotes: 3

Related Questions