Forum Discussion

Maggan Wåhlin's avatar
Maggan Wåhlin
Iron Contributor
Jan 25, 2018

PnPJS graph package problem in SharePoint Framework

Hi,

 

I´m trying to use the new graph-package from PnP (@pnp/graph), and get the following error when running the code in the SP workbench:

 

Uncaught (in promise) TypeError: Cannot read property 'fetchClientFactory' of null
at GraphRuntimeConfigImpl.get [as fetchClientFactory] (localhost:4321/dist/my-groups-web-part.js:2215) 
at new GraphHttpClient (localhost:4321/dist/my-groups-web-part.js:2233)
at Object.clientFactory (localhost:4321/dist/my-groups-web-part.js:2389)

My SPFx-code:

 

import { graph } from "@pnp/graph";
...
public onInit(): Promise<void> {
    return super.onInit().then(_ => {
      graph.setup({
        spfxContext: this.context
      });
    });
  }
...
public render(): void {
    this.domElement.innerHTML = `Loading...`;
    graph.v1.groups.get().then(groups => {
      this.domElement.innerHTML = `Groups: <ul>${groups.map(g => `<li>${g.displayName}</li>`).join("")}</ul>`;
    });
  }

Am I missing something? I´ve created my SPFx-webpart using the latest version of SPFx.

 

Regards,

Margareta

1 Reply

  • Dhaval Shah's avatar
    Dhaval Shah
    Copper Contributor

    Hi Magan,

     

    I am facing the same issue with the old pnp framework as well as the new version of the pnp framework.

    Were you able to find the resolution ?

     

    import pnp from "pnp";
    
    pnp.graph.v1.groups.get().then((result)=>{
    	console.log(result);
    }).catch((error)=>{
    	console.log(error);
    })

    I have also created a similar issue over https://github.com/pnp/pnp/issues/48

    https://github.com/pnp/pnp/issues/48