Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with sp.createIsolated() #10

Open
dannyfoncke opened this issue Jul 8, 2021 · 6 comments
Open

Error with sp.createIsolated() #10

dannyfoncke opened this issue Jul 8, 2021 · 6 comments
Assignees

Comments

@dannyfoncke
Copy link

Hello,
I'm using pnp-auth a lot :) thank you for providing this lib

I'm trying to use isolated sp objects with pnp-auth but I get the following error :

TypeError: safe_global_js_1.safeGlobal.fetch is not a function
(node:13276) UnhandledPromiseRejectionWarning: TypeError: safe_global_js_1.safeGlobal.fetch is not a function
at FetchClient.fetch (C:\Projects\sptoolkit-projects\packages\common\net.ts:66:27)
at SPHttpClient.retry (C:\Projects\sptoolkit-projects\packages\sp\sphttpclient.ts:122:24)
at C:\Projects\sptoolkit-projects\packages\sp\sphttpclient.ts:144:19
at new Promise ()
at SPHttpClient.fetchRaw (C:\Projects\sptoolkit-projects\packages\sp\sphttpclient.ts:142:16)
at SPHttpClient. (C:\Projects\sptoolkit-projects\packages\sp\sphttpclient.ts:82:21)

packages used :

 "@pnp/nodejs-commonjs": "^2.6.0",
  "@pnp/sp-commonjs": "^2.6.0",
   "pnp-auth": "^2.0.0",

Code that produces the error:

   import { bootstrap, } from 'pnp-auth';
   import { sp } from '@pnp/sp-commonjs';
   import { AuthConfig, } from 'node-sp-auth-config'
   
   const isolatedSP = await sp.createIsolated()
   const authConfig = new AuthConfig({
		authOptions: thecredsobject
	});
   bootstrap(isolatedSP, authConfig)

The same code works with the standard sp object (from the import)

     .....
      bootstrap(sp, authConfig)

I hope you can point me to my error or fix the problem ?

thanks again
gr

@koltyakov koltyakov self-assigned this Jul 8, 2021
@koltyakov
Copy link
Member

koltyakov commented Jul 8, 2021

Thanks @dannyfoncke,

We'll take a look. Isolated environments are relatively new and something might be at edge of PnPjs & the auth library. However, messages out of the sphttpclient don't look so good to me.

@koltyakov
Copy link
Member

Hi @dannyfoncke,

I was not able to repro. Bootrapping with isolated sites works for me.

@dannyfoncke
Copy link
Author

dannyfoncke commented Jul 12, 2021

Thanks for investigating @koltyakov

Can the fact that I'm using add-in creds have something to do with it ?
Also I'm targeting SharePoint 2019 on-prem
(I probably should have included that in my question - sorry)

@koltyakov
Copy link
Member

It might be. I've tested user creds to two different SPO tenants.
Have no On-Prem with Add-ins model enabled to check if it's the case.

Can you try if a different auth strategy fails the same for you?
I also used PnPjs v2.7 not 2.6.

@dannyfoncke
Copy link
Author

Sadly upgrading to v2.7 has not resolved the issue

Trying a different auth strategy will take a bit more doing
(Also it will need to be done targeting SP2013)

@dannyfoncke
Copy link
Author

Hello

Update : it seems to be working in version 2.8 with some issues down the line.

Straightforward creating an isolated sp object and using it works in like "isolatedsp.web...." expressions
(I'm on SharePoint 2019 onprem, use add-in creds and the pnp-auth/node-sp-auth-config combo)

Starting from a default created isolatedsp object (no configuration options), this scenario, taken from the pnp documentation, however does not :

const file = await isolatedsp.web.getFolderByServerRelativeUrl("/sites/dev/Shared%20Documents/test/").files.add("file.name", "file", true);
const item = await file.file.getItem();
await item.update({
  Title: "A Title",
  OtherField: "My Other Value"
});

The statement : isolatedsp.web.getFolder...... works
The statement : file.file.getItem() works
The statement item.fileupdate... fails with a TypeError: safe_global_js_1.safeGlobal.fetch is not a function

Thanks again for the work provided on pnp and related libs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants