Forum Discussion

LadislavStupak's avatar
LadislavStupak
Brass Contributor
Jun 22, 2021
Solved

Uncaught (in promise) Error: Error making HttpClient request in queryable [404] Not Found

Dear ladies and gentlemen,

 

I receive following error after deployment of the SPFx solution to SharePoint 2019 App catalog:

 

"Uncaught (in promise) Error: Error making HttpClient request in queryable [404] Not Found"

 

When I run the solution through "gulp serve" everything works well. No errors occur.

 

In methods which use the "sp" object from "pnp" the error occured.

 

Here is one example:

 

import {sp} from '@pnp/sp';

 

public GetListExistsAndContainsItems(listTitle: string): Promise<boolean> {

return new Promise<boolean>(async(resolve, reject) => {

if (listTitle) {

console.log("GetListExistsAndContainsItems - listTitle: " + listTitle);

let listExists: boolean = false;

await sp.web.lists.getByTitle(listTitle).items.select("Id").getAll().then((allItems: any[]) => {

if (allItems) {

listExists = true;

console.log("GetListExistsAndContainsItems - listExists: " + listExists);

resolve(listExists);
}
}).catch((error: any) => {

console.log("GetListExistsAndContainsItems - error: " + error);

reject(error);
})
}
})
}

 

Classic rest api calls through the WebPartContext work well also after deployment of the solution into the app catalog.

 

Only calls through "sp" from "pnp" throw this error only after deployment to app catalog in SharePoint 2019.

 

Thank you for your help.

 

Ladislav Stupak

  • I had to add the onInit method to the web part class and set the context for sp there.

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

    export default class TestPageWebPart extends BaseClientSideWebPart<ITestPageWebPartProps> {

    protected onInit(): Promise<void> {

    sp.setup({

    spfxContext: this.context

    });

    return super.onInit();

    }

    }

    In the test by "gulp serve", "pnp sp" will probably find the context even without this explicit link in the onInit method. After uploading the SPFx solution under SharePoint Apps in SharePoint 2019, this context is not found and must therefore be determined explicitly.

1 Reply

  • I had to add the onInit method to the web part class and set the context for sp there.

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

    export default class TestPageWebPart extends BaseClientSideWebPart<ITestPageWebPartProps> {

    protected onInit(): Promise<void> {

    sp.setup({

    spfxContext: this.context

    });

    return super.onInit();

    }

    }

    In the test by "gulp serve", "pnp sp" will probably find the context even without this explicit link in the onInit method. After uploading the SPFx solution under SharePoint Apps in SharePoint 2019, this context is not found and must therefore be determined explicitly.

Resources