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 Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

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 […]

Leave a Reply

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

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading