Legacy Dev Forum Posts

 View Only

Sign Up

Unable to use JS SDK in Angular 7 web app

  • 1.  Unable to use JS SDK in Angular 7 web app

    Posted 06-05-2025 18:02

    sduque | 2019-05-06 21:29:50 UTC | #1

    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?


    tim.smith | 2019-05-06 22:12:16 UTC | #2

    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


    sduque | 2019-05-06 23:46:40 UTC | #3

    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


    tim.smith | 2019-05-07 19:34:11 UTC | #4

    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.


    sduque | 2019-05-09 16:57:19 UTC | #5

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


    tim.smith | 2019-05-09 20:25:07 UTC | #6

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


    system | 2019-06-09 20:25:08 UTC | #7

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


    This post was migrated from the old Developer Forum.

    ref: 5086