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

TypeError: sp.setup is not a function #12

Open
dma82 opened this issue Jan 17, 2022 · 14 comments
Open

TypeError: sp.setup is not a function #12

dma82 opened this issue Jan 17, 2022 · 14 comments

Comments

@dma82
Copy link

dma82 commented Jan 17, 2022

Hi,

I installed pnp-auth v2.0.0 and @pnp/sp-commonjs v2.11.0 and I'm using them in my project in this way:

const bootstrap = require("pnp-auth").bootstrap;
const taxonomy = import("@pnp/sp-commonjs/taxonomy/index.js");

let url = settings.sharepoint365.url;

bootstrap(taxonomy, {
    username: settings.sharepoint.auth.username, 
    password: settings.sharepoint.auth.password }, 
    url);

But I send my request, I get this error:

C:\my-project\node_modules\pnp-auth\lib\index.js:17
    sp.setup({
       ^

TypeError: sp.setup is not a function
    at bootstrap (C:\my-project\node_modules\pnp-auth\lib\index.js:17:8)
...
..., etc.

Am I doing anything wrong or is this a bug?

Thank you.

@koltyakov
Copy link
Member

Hi @dma82,

To use PnPjs, it's dependencies should be imported.

Please check https://pnp.github.io/pnpjs/getting-started/

Import taxonomy (sub package is not enough).

@dma82
Copy link
Author

dma82 commented Jan 18, 2022

Hi @koltyakov,

Thank you for your reply. Apologies, in my previous example I forgot to show you an extract of my package.json (out of desperation I eventually started to install even the basic libraries (the ones not for CommonJS):

"dependencies": {
   "@pnp/common": "^2.11.0",
   "@pnp/common-commonjs": "^2.11.0",
   "@pnp/graph": "^2.11.0",
   "@pnp/graph-commonjs": "^2.11.0",
   "@pnp/logging": "^2.11.0",
   "@pnp/logging-commonjs": "^2.11.0",
   "@pnp/nodejs": "^2.11.0",
   "@pnp/nodejs-commonjs": "^2.11.0",
   "@pnp/odata": "^2.11.0",
   "@pnp/odata-commonjs": "^2.11.0",
   "@pnp/sp": "^2.11.0",
   "@pnp/sp-commonjs": "^2.11.0",
   ...
   ...
},
"devDependencies": {
   "typescript": "^4.5.4",
   ...
   ...
},
"engines": {
    "node": ">=12.13.0"
}

But despite having all dependencies, I'm getting this nasty error...

Thank you.

Regards,
Davide

@koltyakov
Copy link
Member

koltyakov commented Jan 18, 2022

@dma82, specific PnPjs packages not only should be installed but actually imported. Did you try something structurally like this:

import { bootstrap } from 'pnp-auth';
import { sp } from '@pnp/sp-commonjs';
import "@pnp/sp/taxonomy-commonjs";

bootstrap(sp, authData); 

const info = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72")
  .sets.getById("338666a8-1111-2222-3333-f72471314e72").get();

// ...

@dma82
Copy link
Author

dma82 commented Jan 18, 2022

Hi @koltyakov,

I've tried this but still no joy:

const bootstrap = require("pnp-auth").bootstrap;
const sp = import("@pnp/sp-commonjs/index.js");
const taxonomy = import("@pnp/sp/taxonomy/index.js");

let url = settings.sharepoint.url;

bootstrap(sp,  {
            username: settings.sharepoint.auth.username, 
            password: settings.sharepoint.auth.password }, 
            url);

const set = _.map(await sp.termStores.getByName("<TAXONOMY_NAME>").getTermSetById("<TERM_SET_ID>").terms.get(), 
                    list => _.pick(list, ['Id', 'Name', 'PathOfTerm']));

With pnp-auth v.0.0.4 and sp-taxonomy v.1.3.11 I was able to retrieve the taxonomy list, but those libraries are quite old...

Thank you

@koltyakov
Copy link
Member

LOL, I wanted to ask a fellow from https://github.com/pnp/pnpjs/discussions/2004 discussion who recently was successful with the same setup with taxonomy, but it was you.

@dma82
Copy link
Author

dma82 commented Jan 18, 2022

LOL! Yes it was me, but with the old libraries! With the new ones somehow I'm having issues... Problem is even with the old libraries I'm having loads of "circular dependency" warnings, so it seems no matter what I do I just incur in issues lol!

@dma82
Copy link
Author

dma82 commented Jan 18, 2022

Hi @koltyakov,

Just a quick update: instead of using the import at the beginning of my module, I imported it in my function:

async function getList(req, res, next) { 
        let url = settings.sharepoint.url;

        const sp_ = (await import("@pnp/sp-commonjs/index.js"));
        const taxonomy = await import("@pnp/sp-commonjs/taxonomy/index.js");

        bootstrap(sp_.sp, settings.sharepoint.auth, url);

        const set = (await taxonomy.TermStore("").groups.getById("GROUP_ID").sets.getById("<TERM_SET_ID>").terms.get());

        debug(set);
        next()
}

And now I'm getting a different error lol:

C:\my-project\node_modules\@pnp\odata-commonjs\parsers.js:133
        var _this = _super.call(this, message) || this;
                           ^

Error: Error making HttpClient request in queryable [403] Forbidden ::> {"error":{"code":"notAllowed","message":"OAuth only flow is enabled and the call has not been issued from an app."}}
    at new HttpRequestError (C:\my-project\node_modules\@pnp\odata-commonjs\parsers.js:133:28)
    at Function.<anonymous> (C:\my-project\node_modules\@pnp\odata-commonjs\parsers.js:148:47)
    at step (C:\my-project\node_modules\tslib\tslib.js:143:27)
    at Object.next (C:\my-project\node_modules\tslib\tslib.js:124:57)
    at fulfilled (C:\my-project\node_modules\tslib\tslib.js:114:62)

Same error if I use this:

const set = (await sp_.sp.termStore.groups.getById("GROUP_ID").sets.getById("<TERM_SET_ID>").terms.get());

@dma82
Copy link
Author

dma82 commented Jan 18, 2022

Which bring us back to pnp/pnpjs#2004: that means I'm going round in circle LOL!

@koltyakov
Copy link
Member

@dma82,

Not promising, but let me try to assemble an example with taxonomy. However, could do it only over the weekend. If you’ll manage finding a solution before it, please let me know.

What are the limitations? Just wondering, what are the stoppers for using TypeScript and latest Node.js and latest versions of other ingredients?

@dma82
Copy link
Author

dma82 commented Jan 19, 2022

Hi @koltyakov, I surely will let you know if I manage to find a solution. My limitation for using Typescript is that I need to re-use an existing module in CommonJS so at the present moment I can't migrate the whole solution... With regards to Node, I'm actually using the latest version (v.16).

I don't know if the problem now is the credentials (I'm using username and password) or if I'm trying to retrieve the term store in the wrong way...

Thank you in advance for any help you can give me, much appreciated :)

@koltyakov
Copy link
Member

Just offtopic. TypeScript allows using JS (https://www.typescriptlang.org/tsconfig#allowJs) and allows incremental migration.

@koltyakov
Copy link
Member

Hey @dma82,

Looks that the modern Taxonomy API only can be accessed with Azure AD auth.

There is no such strategy currently in node-sp-auth.

@dma82
Copy link
Author

dma82 commented Jan 24, 2022

Hi @koltyakov ,

Unfortunately I suspected that this strategy was no longer supported but wasn't sure which module was responsible for this...

I might contact their development team and start bugging them lol! :D

Thank you so much for all your time and help on this,, I really appreciated it!

@mplwork
Copy link

mplwork commented Apr 26, 2023

@dma82 I suppose you haven't been successful in the meantime. I just wasted the better half of an afternoon to try the same thing until I stumbled upon this github issue. So no luck with pnp-auth then.

I want to update Taxonomy fields and a test case works, using item.validateUpdateListItem([{FieldName: 'myField', FieldValue: 'taxLabel|taxGUID'}]). But I need taxLabel and taxGUID to do this. Scraping them from the web page is just no option as there are way too many. Are there maybe other methods to get at the required label/GUID combination?

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

3 participants