Azure-sdk-for-js: Getting TypeError: PredictionApiClient is not a constructor

Created on 1 Aug 2019  路  6Comments  路  Source: Azure/azure-sdk-for-js

  • Package Name: @azure/cognitiveservices-customvision-prediction
  • Package Version: 3.0.0
  • Operating system: Windows 10
  • [x] nodejs 12.4.0

    • version:

  • [ ] browser

    • name/version:

  • [ ] typescript

    • version:

  • Is the bug related to documentation in

Describe the bug
I am getting the following error when trying to initiate the prediction API client:

TypeError: PredictionApiClient is not a constructor

To Reproduce
Steps to reproduce the behavior:

  1. Run this:
const PredictionAPIClient   = require("@azure/cognitiveservices-customvision-prediction");
const client = new PredictionAPIClient("<your prediction key>", "<your endpoint>");

Expected behavior
The sample compiles and I can use the prediction API client.

Client Cognitive - Custom Vision Service Attention customer-reported

All 6 comments

Hi @weiligao thanks for taking the time to write up this bug report. I've labeled it for the cognitive services team to take a look.

The require statement returns the entire module, therefore you cannot use new on it.

Change const PredictionAPIClient = to const { PredictionAPIClient } = and you should be able to instantiate the client

The require statement returns the entire module, therefore you cannot use new on it.

Change const PredictionAPIClient = to const { PredictionAPIClient } = and you should be able to instantiate the client

Except for it does not. Now I am getting a "TypeError: PredictionApiClient is not a function"

The below javascript code runs correctly and logs the api key for me

const { PredictionAPIClient }  = require("@azure/cognitiveservices-customvision-prediction");
const client = new PredictionAPIClient("<your prediction key>", "<your endpoint>");
console.log(client.apiKey)

Output:
<your prediction key>

Are you running javascript or typescript code?

Hi, it seems that there is a typo instead of PredictionAPIClient but in the sample provided https://docs.microsoft.com/en-us/azure/cognitive-services/custom-vision-service/node-tutorial, it was PredictionApiClient.

Thanks for reporting the typo @ngcammayo

I have put a PR out to fix the docs, will update this thread once its been merged.

Was this page helpful?
0 / 5 - 0 ratings