microsoftgraph / microsoft-graph-toolkit

Authentication Providers and UI components for Microsoft Graph 🦒
https://docs.microsoft.com/graph/toolkit/overview
Other
938 stars 298 forks source link

[BUG] : 3.0.0-preview.1 : Unable to use mgt-react components in SPFx #2158

Closed anoopt closed 1 year ago

anoopt commented 1 year ago

Describe the bug With v3.0.0-preview.1 of mgt-react, when an mgt-react component is used in an SFPx web part, we get an error saying - Script error for: @microsoft/microsoft-graph-client http://requirejs.org/docs/errors.html#scripterror

To Reproduce Steps to reproduce the behavior:

  1. Create an SFPx web part (with react as the framework)
  2. Add @microsoft/mgt-spfx and @microsoft/mgt-react packages - version 3.0.0-preview.1
  3. Setup the web part with provider and add an mgt-react component as mentioned here skipping the library part.
  4. Run the code
  5. Add the web part on to a page

Code added in the component

import { Person } from '@microsoft/mgt-react';
// import { Person } from '@microsoft/mgt-react/dist/es6/spfx';
// import { Person } from '@microsoft/mgt-react/dist/es6/generated/react';
...
...
// in render
<Person personQuery="me"></Person>

Expected behavior The mgt-react component should load in the web part.

Screenshots

On web part load: image

Logs from console: image

Another type of error that is seen sometimes on web part load: image

Environment (please complete the following information):

Additional context Tried the same by deploying @microsoft/mgt-spfx SharePoint Framework package to the tenant and still get the same error.

ghost commented 1 year ago

Hello anoopt, 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 🙌

sebastienlevert commented 1 year ago

You would not need mgt-spfx per my understanding. Do you get the same results without the library component package?

anoopt commented 1 year ago

Thanks Seb. Yes. I tried without (and with) the library component. I see the same error.

sebastienlevert commented 1 year ago

There are issues currently with SPFx and MGT in v3. The mgt-spfx-utils has issues with the package and this makes it fail. We are looking into it and will fix for our next preview drop!

anoopt commented 1 year ago

Thank you for the update @sebastienlevert

gavinbarron commented 1 year ago

I think that the underlying culprit here is that SharePoint is treating the @microsoft/microsoft-graph-client as a library component. The latest version of the graph client library is 3.0.5 while the SharePoint infrastructure has 3.0.2 as the highest available version.

This is really unfortunate that SharePoint is not able to serve a lower patch version. Our best bet here is to pin all of our libraries to use 3.0.2 explicitly rather than the ^3.0.0 server range we currently use.

gavinbarron commented 1 year ago

@anoopt this is fixed in v3.0.0-preview.2 which was released today :)

anoopt commented 1 year ago

Brilliant all ok now :)