Unable to use JS SDK in Angular 7 web app

I'm unable to use the PureCloud platform JS SDK in an Angular 7 project.

The sdk was installed following these steps:

  1. npm install purecloud-platform-client-v2
  2. Edit angular.json to include "./node_modules/purecloud-platform-client-v2/dist/web-cjs/purecloud-platform-client-v2.min.js" in scripts property.
  3. Use it in AppComponent this way:
import { Component, OnInit } from '@angular/core';
import * as platformClient from 'purecloud-platform-client-v2';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
  title = 'myapp';

  ngOnInit(): void {

    const client = platformClient.ApiClient.instance;
    console.log(client);
  }
}

This is the current result:

What is the correct usage of the JS SDK for an Angular project?

1 Like

I've never tried it in angular, but it might be import platformClient from 'purecloud-platform-client-v2'; as demonstrated here in a react test app. There's some general information about the setup of that app in the readme in https://github.com/MyPureCloud/platform-client-sdk-javascript-beta.

You can also consume the non-transpiled ES6 source classes directly from https://github.com/MyPureCloud/platform-client-sdk-javascript/tree/master/build/src/purecloud-platform-client-v2

Thanks for the reply @tim.smith , it is not working as 'purecloud-platform-client-v2' does not have a default export. That's why I'm importing it using * as platformClient.

Here you can find the example at StackBlitz https://stackblitz.com/edit/angular-purecloud

I think angular is defaulting to the CJS module from the package. My guess is that you'll need to configure angular and webpack to use the jsnext:main entry point in the package as was done in the react example I linked. That should allow it to use the raw ES6 classes instead of the transpiled module. I don't know how to accomplish that in angular though.

Is the configuration to use the jsnext:main entry point you are talking about the one done here?

Yes, I believe that is what tells webpack in what order to choose entry points from packages.

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