spfx pnp 404 when getting myProperties
-
08-02-2021 - |
Вопрос
I try to fetch my properties using the sp.profiles.myProperties.get()
from @pnp/sp.
It works on a hosted workbench but when I deployed the package and run it on Sharepoint site page I'm getting Error making HttpClient request in queryable [404] Not Found
Why is that so and how can I fix it?
Решение
Looks like you are missing the inital setup which is necessary to determine the request URLs in SPFx context.
In your webpart.ts file, add the below piece of code:
import { sp } from "@pnp/sp/presets/all";
// ...
protected onInit(): Promise<void> {
return super.onInit().then(_ => {
// other init code may be present
sp.setup({
spfxContext: this.context
});
});
}
// ...
Reference - PnPJS getting started
Не связан с sharepoint.stackexchange