reactjstypescriptspfxpnp-js

Attempting to add multiple items to SP list using sp/pnp but getting error on ```createBatch()```


I'm following this documentation: https://pnp.github.io/pnpjs/sp/items/#add-multiple-items But I'm getting an error with:

import { SPFI, spfi, SPFx } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/lists";
import "@pnp/sp/items";
import "@pnp/sp/comments"
import "@pnp/sp/site-users/web";

let sp: SPFI;

export const CreateTableItems = async (listName: string, items: IMoscow) => {
    const batch = sp.web.createBatch()
};

It's saying Property 'createBatch' does not exist on type 'IWeb & IInvokable<any>'.

I'm clearly missing something but the docs don't make it clear. I'm using the latest v3 version of sp/pnp and I am able to submit/update single items fine.


Solution

  • Maybe you've lost this import. import "@pnp/sp/batching";

    https://learn.microsoft.com/es-es/sharepoint/dev/spfx/web-parts/guidance/use-sp-pnp-js-with-spfx-web-parts