reCaptcha Enterprise assessment Node.js code breaks on unexpected '.'

I'm trying to set up reCaptcha Enterprise in a React/Node.js application. I have successfully set up the reCaptcha to work on the frontend and it is generating a token and passing it to the backend for assessment. The problem I can't seem to get around is the Node.js assessment example code from Google breaks, giving a the message SyntaxError: Unexpected token '.'. Specifically, this seems to happen when creating a new RecaptchaEnterpriseServiceClient. I suspect there might be an issue with authentication using Application Default Credentials, but I haven't seen any evidence of errors in the backend logging.

First, in the Google Cloud Console I give my IAM user roles for reCAPTCHA Enterprise Admin and reCAPTCHA Enterprise Agent.

I'm running the backend in Docker. I use the gcloud cli to authenticate my IAM user on my host machine, generate the ADC and mount it on the backend container using docker compose.

I added the environment variable for pointing the service to the ADC on my docker image (GOOGLE_APPLICATION_CREDENTIALS="/gcp/creds.json")

I'm using the Node.js example code at https://cloud.google.com/recaptcha-enterprise/docs/create-assessment-website  , creating a component with that which I call from my 'signup' controller. I'm able to console log the project, token, key and action string fine. However, the code gives me an error on unexpected token '.' as soon as 

const client = new RecaptchaEnterpriseServiceClient() is executed.

I have been assuming this has something to do with ADC, but have nothing else to go on except that one error message.
1 1 153
1 REPLY 1

Hello @jblackenduro ,

The error message "SyntaxError: Unexpected token" typically indicates that there is a problem with the syntax in the code such as features not supported by the version of the node.js running.

You may consider checking the node.js version compatibility with the features used in the library. You can check the package.json file for the correct package version and run "npm install" to ensure the dependencies are installed.