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)? Nov 8, 2020 at 3:41
  • Yes I am [O365Url]/sites/LimitTester/_layouts/15/workbench.aspx#
    – Billy P
    Nov 8, 2020 at 5:05
  • @Hawk, Is there any update ? Have you tried the solution in the answer ?
    – Jerry
    Nov 11, 2020 at 1:01

1 Answer 1


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 and acknowledge you have read our privacy policy.

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