Angular - platformClient.ApiClient.instance is undefiend

Hi,

I'm trying to build a angular application. I installed and import purecloud-platform-client-v2 package with version 191.0.0

However, I got the an error on:

ERROR TypeError: Cannot read properties of undefined (reading 'instance')

I create a function

private loginClient() {
    const clientConfig = {
      clientId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
      clientSecret: 'yyyyyyyyyyyyyyyyyyyyyyyy',
      redirectUri: 'http://localhost:4200/'
    }
    const client = platformClient.ApiClient.instance;
    client.loginClientCredentialsGrant(clientConfig.clientId, clientConfig.clientSecret)
      .then(() => {
        // Do authenticated things
      })
      .catch((err) => {
        // Handle failure response
        console.log(err);
      });

  }

where the import is

import * as platformClient from 'purecloud-platform-client-v2';

I have noticed that platformClient is an empty object and therefore platformClient.ApiClient is null.

After checking the forum I found the problem, this is because Webpack looks at the purecloud-platform-client-v2 package.json, and uses the value in the browser field, which points to dist/web-cjs/purecloud-platform-client-v2.min.js. However, what is really needed is the ES6 entry point in src/purecloud-platform-client-v2.

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