In this SPFx tutorial, we will discuss how to fix the error, error ts2307 cannot find module ‘@pnp/sp/presets/all’ which comes while working with SPFx client-side web parts. It also solved the below issues:
- cannot find module ‘@pnp/sp/presets/all’
- cannot find module ‘@pnp/sp/presets/all’.ts(2307)
- error ts2307 cannot find module ‘@pnp/sp/presets/all’
Recently, I was working on a SharePoint framework crud operations with no javascript framework solution, and when I run the gulp server cmdlets, I received the below error:
error TS2307 cannot find module ‘@pnp/sp/presets/all’
You can see the screenshot:
Let us see how to fix the error, cannot find module ‘@pnp/sp/presets/all’.
You can also check the code, Cannot find module ‘@pnp/sp/presets/all’ or its corresponding type declarations.
Error TS2307 Cannot find module @pnp/sp/presets/all
As you can see here from the error message the issue is related to the PnP. I was using PnP for the SPFx CRUD operations.
Since I downloaded the SPFx project from a backup and I just run the below command to install the node_modules.
npm i
But since, I was using the PnP and the below import statements, we need to install PnP as well.
import { sp, Web, IWeb } from "@pnp/sp/presets/all";
import "@pnp/sp/lists";
import "@pnp/sp/items";
To fix the issues run the below command in the same project or solution directory.
npm i @pnp/sp
Once you run the above command, the error cannot find module ‘@pnp/sp/presets/all’.ts(2307) will not come. And you can run the gulp serve cmdlet to run the SPFx project.
You may like the following SPFx tutorials:
- Setup SharePoint Framework (SPFx) development environment in Windows 10 workstation
- SPFx – Bind dropdown list from SharePoint list using PnP
- How to get user details using Microsoft Graph API in SPFx
- SharePoint online spfx script editor web part
- How to Send Email with Attachments using Graph API in SPFx (React JS)
- cannot find module jquery spfx
- type ‘string’ is not assignable to type ‘number’.ts
I hope this SPFx tutorial helps to fix the error, error ts2307 cannot find module ‘@pnp/sp/presets/all’ in SharePoint Framework (SPFx).
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.
npm i @pnp/[email protected]
this version (2.11.0) resolved my issue