Forum Discussion

Mccartc11025's avatar
Mccartc11025
Copper Contributor
Jun 08, 2023

SPFx webpart doesn't work after deploy

Hi,

We have a webpart that when run on the workbench works as expected. Its using PnP to get the user profile and then searches a list to find list items. 

The webpart fails with the call to the Profile Service no error shown on screen, but in the console log we have the following

Any help please as its doing my head in.

Thanks

2 Replies

  • Mccartc11025 did you supply the web part context to PnP JS library while using it within SPFx? 

     

    Example

     

    import pnp from "sp-pnp-js";
    
    // ...
    
    public onInit(): Promise<void> {
    
      return super.onInit().then(_ => {
    
        pnp.setup({
          spfxContext: this.context
        });
        
      });
    }

     

    Above code might differ based on the version of PnP JS you are using. Check below threads for more details: 

    1. Using @pnp/sp setup  
    2. Web-Part works on localhost, but it does not working on SPO 

    Also, make sure you are using --ship while bundling and packaging the solution, like: 

     

    gulp bundle --ship
    gulp package-solution --ship

     


    Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.