microsoft-graph-toolkit icon indicating copy to clipboard operation
microsoft-graph-toolkit copied to clipboard

Cannot set property 'globalProvider' of undefined while using SimpleProvider for mgt-people-picker

Open sagardeshpande85 opened this issue 6 years ago • 5 comments

The code worked fine in all the environments until few hours back when we suddenly started getting the below error in browser console while working with mgt-people-picker using SimpleProvider.

Error from browser console - Uncaught TypeError: Cannot set property 'globalProvider' of undefined

Code - below highlighted line throwing error

myMSALObj.handleRedirectCallback(authRedirectCallBack);

below line not returning object to globalProvider

mgt.Providers.globalProvider = new mgt.SimpleProvider(async function (scopes) {
    var request = { scopes: scopes };

    try {
        let response = await myMSALObj.acquireTokenSilent(requestObj);
        console.log(response.accessToken);
        return response.accessToken;
    }
    catch (error) {
        if (requiresInteraction(error.errorCode)) {
            myMSALObj.acquireTokenPopup(requestObj);
        }
    }
});

Exception in Browser Watch for mgt.SimpleProvider arguments and caller - TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.invokeGetter (:1:142)

sagardeshpande85 avatar Sep 22 '20 10:09 sagardeshpande85

Hello sagardeshpande85, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

ghost avatar Sep 22 '20 10:09 ghost

@sagardeshpande85 , thanks for submitting this. I know exactly what the issue is! Yesterday we released out next preview, 2.0.0-preview.1.

It looks like you are using the hosted version via unpkg, which is always updated to the latest release. This means you are now pulling down our preview version. There are some breaking changes in V2, which is probably why you are seeing errors: <script src="https://unpkg.com/@microsoft/mgt/dist/bundle/mgt-loader.js

To workaround, update your link to pull the latest production release version: <script src="https://unpkg.com/@microsoft/[email protected]/dist/bundle/mgt-loader.js"></script>

Alternatively, you can also use npm to download the package with the required version listed in the package.json. npm i @microsoft/[email protected]

shweaver-MSFT avatar Sep 22 '20 23:09 shweaver-MSFT

Hi @shweaver-MSFT Thank you for the response. As you pointed correctly, we were using hosted version via unpkg which caused this issue. After replacing it with v1.3.4 it started working as expected. One question - Could we continue to use below 1.3.4 version without any issue or would there be any change in this version (I believe the changes would be released as part of next version v2.0.0 and v1.3.4 will remain as is, but just want to confirm with you.)

sagardeshpande85 avatar Sep 23 '20 09:09 sagardeshpande85

@sagardeshpande85, you can continue to use the 1.3.4 version from unpkg going forward. This version will remain stable. I like the extra control of specifying the version, because when V2 is finally officially released you get to decide when to make the switch.

shweaver-MSFT avatar Sep 23 '20 17:09 shweaver-MSFT

Hi @shweaver-MSFT this worked for me also. Thanks

sps-smith avatar Sep 25 '20 21:09 sps-smith