I am trying out pnpjs USING SharePoint framework and adding new item to my list.

But when I try to gulp serve and run it inside my SharePoint Online

const iar: IItemAddResult = await sp.web.lists.getByTitle(ListName).items.add({
    Title: "Title",

When I try to run its trying to get the information in my list but it has "_layouts/15" on it.

  • Are you running this on SharePoint workbench (_layouts/workbench.aspx)? – Ganesh Sanap Nov 8 '20 at 3:41
  • Yes I am [O365Url]/sites/LimitTester/_layouts/15/workbench.aspx# – Hawk Nov 8 '20 at 5:05
  • @Hawk, Is there any update ? Have you tried the solution in the answer ? – Jerry_MSFT Nov 11 '20 at 1:01

Need to set up correct spfxContent like this in WebPartName.ts:

public onInit(): Promise<void> {

  return super.onInit().then(_ => {

    // other init code may be present

      spfxContext: this.context

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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