1

I have imported the MSGraphClient in my project using the following statement:

import { MSGraphClient } from '@microsoft/sp-client-preview';

I have also added those two import statements, as I will be working with O365 groups:

import { Group } from '@microsoft/microsoft-graph-types';
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';

So far my page is being rendered within the SharePoint workbench without errors. However, as soon as I declare the MSGraphClient in the following manner:

const graphClient: MSGraphClient = this.props.context.serviceScope.consume(MSGraphClient.serviceKey); , the page doesn't load anymore, but begins producing errors of this type:

enter image description here

This used to work in a past project of mine, I am not sure what has changed. I considered importing the MSGraphClient from'@microsoft/sp-http' as per the official documentation (https://docs.microsoft.com/en-us/sharepoint/dev/spfx/use-msgraph), but VS Code doesn't even allow me to do that.

2
  • What version of the SharePoint framework are you on?
    – baywet
    Commented Feb 3, 2019 at 19:55
  • must be 1.5.1? Here en extract from my package.json file: "dependencies": { "react": "15.6.2", "react-dom": "15.6.2", "@types/react": "15.6.6", "@types/react-dom": "15.5.6", "@microsoft/sp-core-library": "1.5.1", "@microsoft/sp-webpart-base": "1.5.1", "@microsoft/sp-lodash-subset": "1.5.1", "@microsoft/sp-office-ui-fabric-core": "1.5.1", "@types/webpack-env": "1.13.1", "@types/es6-promise": "0.0.33" } Commented Feb 4, 2019 at 9:45

1 Answer 1

0

I think you are having multiple issues here:

  • Your node_modules folder contains bad dependencies, either duplicates on different versions or a corrupted installation. First try to run npm dedupe to see if it helps solving anything (read other points first). If it doesn't, delete the folder, delete the package-lock.json and try installing again.
  • Then your import should be import { MSGraphClient } from '@microsoft/sp-http';, you should update that.
  • Lastly the API to get the MSGraphHttpClient if the following this.context.msGraphClientFactory.getClient() and not what you've been suggesting.

I suggest you make the code changes first, and then fix the module installation issue.

1
  • thank you for your help! ended up creating an entirely new project (fortunately didn't have much to lose) and updated manually all the SPFx components to 1.6.0 (the yeoman generator is creating the project using 1.5.1 by default); it finally works, using the import statement, mentioned in the official documentation and declaring the variable the way you've described it. Commented Feb 10, 2019 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.