Import Web is not working for accessing another site in SPFX
Hub-GHS opened this issue · comments
Hub-GHS commented
Type of issue
The below code works fine on lists in the same site collection, but not on lists in a different site collection
Using the below in package.json
"@pnp/common": "1.3.3",
"@pnp/logging" :"1.3.3",
"@pnp/odata":"1.3.3",
"@pnp/sp":"1.3.3"
import { sp, Web } from '@pnp/sp';
const targetSiteCollectionUrl = "https://anothersitecollectionURL";
const web = new Web(targetSiteCollectionUrl);
sp.setup({
sp: {
baseUrl: targetSiteCollectionUrl,
},
});
let listItems = await web.lists.getByTitle("TeamInfo").items.get();
console.log(listItems.length);
My environment
Windows 10 64-bit
Node Version v10.24.1
NPM Version - 6.14.2
yo - 3.1.1