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:
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.
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
requirestatement returns the entire module, therefore you cannot usenewon it.Change
const PredictionAPIClient =toconst { 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.