Getting the error tslib.js:113 Uncaught (in promise) TypeError: _this.provider is not a function

Gabriel Costa 1 Reputation point
2021-03-01T20:57:34.463+00:00

I got the code below to create a user:

const msalConfig = {    
        auth: {    
            clientId:  "Ive substituted this for my clientId",     
            redirectUri: "Ive substituted this for my URL",    
        },    
    };    
    const graphScopes = ["user.read", "mail.send"];     

    const msalApplication = new UserAgentApplication(msalConfig);    
    const options = new MSALAuthenticationProviderOptions(graphScopes);    
    const authProvider = new ImplicitMSALAuthenticationProvider(msalApplication, options);    
        
    const options2 = {    
        authProvider,    
    };    
        
    const client = Client.init(options2);    
        
    const user = {    
      accountEnabled: true,    
      displayName: "Adele Vance",    
      mailNickname: "AdeleV",    
      userPrincipalName: "AdeleV[@](/users/na/?userId=a28c79c1-c609-48db-b55f-1783d1187afb).onmicrosoft.com",    
      "passwordProfile" : {    
        forceChangePasswordNextSignIn: true,    
        password: "xWwvJ]6NMw+bWH-d"    
      }    
    };    
        
    let res = client.api('/users')    
        .post(user);    
})    

But I get the following error: tslib.js:113 Uncaught (in promise) TypeError: _this.provider is not a function

Can anybody help me?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,592 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Vicky Kumar (Mindtree Consulting PVT LTD) 1,156 Reputation points Microsoft Employee
    2022-06-14T12:23:07.86+00:00

    Have you initialized the provider in JavaScript?

    import {Providers, MsalProvider} from '@microsoft/mgt'
    import {UserAgentApplication} from "msal";

    Providers.globalProvider = new MsalProvider(config: MsalConfig);

    ref doc - https://learn.microsoft.com/en-us/graph/toolkit/providers/msal#initialize-in-javascript

    0 comments No comments