Please specify what version of the library you are using: [
"@pnp/common": "^2.1.0-beta8",
"@pnp/graph": "^2.1.0-beta8",
"@pnp/logging": "^2.1.0-beta8",
"@pnp/odata": "^2.1.0-beta8",
]
Please specify what version(s) of SharePoint you are targeting: [ Online ]
If you are not using the latest release, please update and see if the issue is resolved before submitting an issue.
attempting to obtain the current users company attribute using:
graph.me.select("companyName")
`constructor(context: ISPFXContext) {
sp.setup({
spfxContext: context,
});
graph.setup({
spfxContext: context
});
pnpSetup({
spfxContext: context
});
}
public getCurrentUserCompany(): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
try {
let user = await graph.me.select('companyName').get();
resolve(user.companyName);
} catch (error) {
reject("exception");
console.error(error);
}
resolve('');
});
}`
graph.me is undefined
Hey @lvasiliou,
I'm a bit confused about something... is the array of objects you included in the versions what's in your package.json, if so, you only need to import @pnp/sp and @pnp/graph... you can see the details in the getting started documentation.
Regarding the error you're getting, did you import @pnp/graph/users -- see docs? I can't tell from your code snippet.
Hi the additional packages are used elsewhere in the solution. I felt it is best to keep everything pnpjs in line.
The import is in place indeed
import { ISPFXContext } from '@pnp/common';
import { graph } from '@pnp/graph';
import "@pnp/graph/users";
import { sp } from '@pnp/sp';
import { setup as pnpSetup } from "@pnp/common";
import "@pnp/sp/taxonomy";
import { ICompany } from '../models/ICompany';
import { Constants } from '../Constants';
export class OpcoService {
constructor(context: ISPFXContext) {
sp.setup({
spfxContext: context,
});
graph.setup({
spfxContext: context
});
pnpSetup({
spfxContext: context
});
}
public getCurrentUserCompany(): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
try {
let user = await graph.me.select('companyName').get();
resolve(user.companyName);
} catch (error) {
reject("exception");
console.error(error);
}
resolve('');
});
}
public getConfiguredOpcos(): Promise<ICompany[]> {
return new Promise<ICompany[]>(async (resolve, reject) => {
try {
let x = await sp.termStore.groups.getById(Constants.OPCO_TERMGROUP_ID).sets.getById(Constants.OPCO_TERMSET_ID).children();
let currentUserOpCo = await this.getCurrentUserCompany();
let returnArray: ICompany[] = [];
for (let i = 0; i < x.length; i++) {
const element = x[i];
let label = element.labels[0].name;
let userOpCo = label.toLowerCase().trim() == currentUserOpCo.trim().toLowerCase();
let y = { name: label, termId: element.id, userCompany: userOpCo };
returnArray.push(y);
}
resolve(returnArray);
}
catch (error) {
reject(error);
console.error(error);
}
});
}
}
Hi the additional packages are used elsewhere in the solution.
The point I'm making is that your package.json should only include
...
"@pnp/graph": "^2.1.0-beta8",
"@pnp/sp": "^2.1.0-beta8",
...
because common, odata, logging are already included in it.
This line also should be removed as it's for a previous version of the library:
pnpSetup({
spfxContext: context
});
You would then also not need this import
import { setup as pnpSetup } from "@pnp/common";
and this import
import { ISPFXContext } from '@pnp/common';
would be replaced with
import { IWebPartContext } from "@microsoft/sp-webpart-base";
but that's assuming that the context is coming from SPFx web part... which may not be the case at all.
For this, can you link to a full project we can check out? Hard to understand how all the pieces fit together. My guess is that you are including the "users" stuff in one file that isn't being run so the import doesn't happen within the closure of the other file.
Hi i removed the two packages and also added the imports in the calling react component to no change.
Project can be found here https://1drv.ms/u/s!Aig9DkHRnxUoraJKkMfqSG7BW6YqNQ?e=3ea1IR
Hi @lvasiliou - haven't had a chance to check your code (will do) but just published a new beta. I don't think it will make a difference but could you please give it a go just to be sure if you have a moment. Will look at your code/etc when I have some time. Thanks!
Hi I tried out 2.1.0-beta9 with the same issue on calling graph.me.select
TypeError: Cannot read property 'fetchClientFactory' of undefined
at new GraphHttpClient (e:\repos\Launchpad\dist\node_modules\@pnp\graph\graphhttpclient.js:12:1)
at Object.clientFactory (e:\repos\Launchpad\dist\node_modules\@pnp\graph\operations.js:9:1)
at e:\repos\Launchpad\dist\node_modules\@pnp\odata\pipeline.js:152:1
at new Promise (<anonymous>)
at Function.send (e:\repos\Launchpad\dist\node_modules\@pnp\odata\pipeline.js:137:1)
at descriptor.value (e:\repos\Launchpad\dist\node_modules\@pnp\odata\pipeline.js:71:1)
at next (e:\repos\Launchpad\dist\node_modules\@pnp\odata\pipeline.js:34:1)
Thanks, will have a look.
Confirmed this is a bug with the new isolated runtime logics, thanks for testing and reporting! Will get it fixed for 2.1.0.
Just published a new beta that fixes this. Thanks again for reporting the issue - please test again when you have a chance and confirm things are working for you.