SPFX : Resolving error – Module “@pnp/sp” has no exported member ‘sp’.ts(2305)

SPFx component = Error while importing member 'sp' from module - "@pnp/sp/"
SPFx component = Error while importing member 'sp' from module - "@pnp/sp/"

Hi All,

Greetings for the day ! Today new issue and solution!

Background:

  • Implementing SPFx component – “demoapp” to get the SharePoint list data and show in some form on UI
  • So installed module “@pnp/sp” using npm as

npm install @pnp/sp 

  • We have module get installed successfully and started implementation
  • In our demoapp.tsx file we have imported member ‘sp’ from module “@pnp/sp/” as

import {sp} from "@pnp/sp/"

  • While importing “sp” member we are getting an error

Error / Issue :

Module “@pnp/sp” has no exported member ‘sp’.ts(2305)

SPFx component = Error while importing member 'sp' from module - "@pnp/sp/"
fig: SPFx component = Error while importing member ‘sp’ from module – “@pnp/sp/”

Solution / Cause :

  • I have installed the latest version on module – “@pnp/sp
  • I could see the version of this module from my package.json file as

 "@pnp/sp": "^3.1.0"

fig: SPFx component = Version of module – “@pnp/sp/” – project.json file

  • This is the PnPjs version 3
  • In PnPjs version 3 the sp and graph objects have been deprecated and will need to be replaced by the new objects like spfi and graphfi – In next article I will demonstrate spfi object
  • Still there are few options if we dont want to go with latest version and continue with our older version of PnPjs and one of them is
    • Uninstall the recent / latest version of PnPjs
    • Install Version 2 of PnPjs as

npm uninstall @pnp/sp

npm i @pnp/sp@2.11.0

Recommendation : Best practice or recommendation is – go with latest version. Microsoft has provided detailed transition guide for transition from Version 2 to Version 3- please have a look once – https://pnp.github.io/pnpjs/transition-guide/

Thanks for reading! Please feel free to discuss in case any issue / suggestion / questions

HAVE A GREAT TIME !!

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

1 Response

  1. March 25, 2022

    […] discussed in last article – SPFX : Resolving error – Module “@pnp/sp” has no exported member ‘sp’.ts(2305) , In PnPjs version 3 we are using SPFI member from module “@pnp/sp” module […]

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: