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).
I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SPGuides.com