Aymkdn / SharepointPlus

SharepointPlus ($SP) is a JavaScript library which offers some extended features for SharePoint entirely on client side (requires no server install). $SP will simplify your interactions with Sharepoint.
http://aymkdn.github.io/SharepointPlus/
GNU Lesser General Public License v3.0
222 stars 57 forks source link

sp.lists gives `ReferenceError: window is not defined` #178

Closed claire-lovisa closed 2 years ago

claire-lovisa commented 2 years ago

Hello !

I'm trying to get the list of all the sharepoint lists of a website from Node.js like this :

    const credentialOptions = {
      username: '<blabla>',
      password: '<blibli>'
    };

    const sp = $SP().auth(credentialOptions);
    sp.lists("<blublu>").then(function(lists) {
      for (var i=0; i<lists.length; i++) console.log("List #"+i+": "+lists[i].Name);
    });

but I'm getting the following error, which kind of makes sense because I'm not in a browser when calling it. Is there a way to bypass this that I didn't see in the documentation ?

 (node:604093) UnhandledPromiseRejectionWarning: ReferenceError: window is not defined
     at SharepointPlus._callee$ (/usr/src/build/node_modules/sharepointplus/dist/utils/getURL.js:49:13)
     at tryCatch (/usr/src/build/node_modules/regenerator-runtime/runtime.js:63:40)
     at Generator.invoke [as _invoke] (/usr/src/build/node_modules/regenerator-runtime/runtime.js:294:22)
     at Generator.next (/usr/src/build/node_modules/regenerator-runtime/runtime.js:119:21)
     at asyncGeneratorStep (/usr/src/build/node_modules/@babel/runtime-corejs3/helpers/asyncToGenerator.js:5:24)
     at _next (/usr/src/build/node_modules/@babel/runtime-corejs3/helpers/asyncToGenerator.js:27:9)
     at /usr/src/build/node_modules/@babel/runtime-corejs3/helpers/asyncToGenerator.js:34:7
     at new Promise (<anonymous>)
     at new Wrapper (/usr/src/build/node_modules/core-js-pure/internals/export.js:18:24)
     at SharepointPlus.<anonymous> (/usr/src/build/node_modules/@babel/runtime-corejs3/helpers/asyncToGenerator.js:23:12)
 (node:604093) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 6)

Thanks a lot !

Aymkdn commented 2 years ago

It should be called as:

sp.lists({url:"https://website"}).then....
claire-lovisa commented 2 years ago

Aah indeed, it works now ! Thanks you for your super fast answer !