Error trying to use platformclient sdk in typescript

Hello,

I am trying to use the platform client sdk in the browser with typescript. Although no errors show in the code itself, when I try to execute the code in the browser, I get the following error:

Uncaught TypeError: purecloud_platform_client_v2_1.ApiClientClass is not a constructor

I suspect the issue may be with the import statement since we've seen something similar before when trying to use our own module, but I'm not sure how to go about fixing it for a third party module.

The code throwing the error is

this._authClient = new ApiClientClass().instance;

and the current import statement is

import {ApiClientClass} from "purecloud-platform-client-v2";

Ultimately, this will come down to how you're importing the package. You may need to alter your compiler's config (webpack, rollup, etc) to import the package correctly. There's an example using React here: https://developer.genesys.cloud/blueprints/react-app-with-genesys-cloud-sdk/

I changed the import to "purecloud-platform-client-v2/dist/node/purecloud-platform-client-v2.js", but I then got issues with webpack:

I added target: 'node' to our webpack config and it then built with the following warnings:

But then threw this error in the browser:

I'm not sure what else to try.

I was able to resolve the issue by leaving the original import (""purecloud-platform-client-v2") and adding the following to our webpack config:

externals: {
            'purecloud-platform-client-v2': "require('platformClient')",
}

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.