pnp / pnpjs

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs
https://pnp.github.io/pnpjs/
Other
763 stars 304 forks source link

Following example causes error "Can't resolve '@pnp/sp-admin'" #2859

Closed Ofer-Gal closed 11 months ago

Ofer-Gal commented 11 months ago

Major Version

3.x

Minor Version Number

21

Target environment

SharePoint Framework

Additional environment details

The example in https://pnp.github.io/pnpjs/sp-admin/#siteproperties shows:

import { spfi } from "@pnp/sp";
import "@pnp/sp-admin";
const sp = spfi(...);
// default props
const defaultProps = await sp.admin.siteProperties();
// all props
const allProps = await sp.admin.siteProperties.select("*")();

But there is an error "Can't resolve '@pnp/sp-admin'" Is the error in the documentation or the library? Thanks

Expected or Desired Behavior

Tring to get Site Name from SharePoint

Observed Behavior

error "Can't resolve '@pnp/sp-admin'"

Steps to Reproduce

import "@pnp/sp-admin";

bcameron1231 commented 11 months ago

Everything looks correct to me, and I can't reproduce your issue.

To better understand what's wrong, can you give us following info: OS SPFx? (if so what version), Node.js version SharePoint version (Online, 2019, 2016,...)

Ofer-Gal commented 11 months ago

OS win 11 SPFx 1.17.2 (React 17.0.1) node v16.19.0 SharePoint Online gulp serve Shows

[16:39:09] Error - [webpack] 'dist':
./lib/hooks/useSPProject.js
Module not found: Error: Can't resolve '@pnp/sp-admin' in 'D:\DATA\Sources\Repos\Ace3.0\Ace3OneJobScreen\lib\hooks'    
resolve '@pnp/sp-admin' in 'D:\DATA\Sources\Repos\Ace3.0\Ace3OneJobScreen\lib\hooks'
juliemturner commented 11 months ago

Did you install the package in your package.json?

https://www.npmjs.com/package/@pnp/sp-admin

Ofer-Gal commented 11 months ago

Oops No. I am used to everything in the 2

juliemturner commented 11 months ago

I'm assuming you understand that the package is really not intended for SPFx solutions. In that you need to be a SharePoint Admin for them to work. I suppose if you were going to write an admin dashboard or something, but the general idea was for nodejs "server" apps, i.e. automation scenarios.

Ofer-Gal commented 11 months ago

No I did not and thanks for the warning. I was just looking for a way to get the site's name from its URL. (for any user) Guess, this isn't the way to do it then.

github-actions[bot] commented 10 months ago

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.