Please specify what version of the library you are using: [1.3.3]
Please specify what version(s) of SharePoint you are targeting: [Sharepoint Online]
I am trying to connect to my SharePoint site using node for testing using sp.setup
I receive an error Error: Cannot find module '.'
Error: Cannot find module '.'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at C:\Users\Chris\source\repos\spnodeapp\node_modules\@pnp\nodejs\dist\nodejs.es5.umd.js:11:217
at Object.<anonymous> (C:\Users\Chris\source\repos\spnodeapp\node_modules\@pnp\nodejs\dist\nodejs.es5.umd.js:14:2)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
I followed all steps from here to register and grant access:
https://social.technet.microsoft.com/wiki/contents/articles/52893.sharepoint-framework-introduction-to-test-driven-development-tdd-using-jest-enzyme.aspx
I first encountered the error trying to connect from a unit test.
I then tried to test by removing everything except exactly what I should need to connect and here is my code for that.
import { sp } from "@pnp/sp";
import { SPFetchClient} from "@pnp/nodejs";
sp.setup({
sp: {
fetchClientFactory: () => {
return new SPFetchClient("https://nameredacted.sharepoint.com", "redacted", "");
},
},
});
sp.web.select("Title").get().then(w => {
console.log(`Web Title: ${w.Title}`);
});
As part of trying to get this to work, I have followed several different examples all with the same result.
Here is a self-contained example that causes the issue for me if I follow the instructions exactly.
https://www.c-sharpcorner.com/article/client-side-development-with-sharepoint-using-nodejs-and-pnp3/
Something strange is going on in SPFetchClient if I return {} instead of SPFetchClient I don't get the Error: Cannot find module '.' instead I get a different error about headers being missing.
This is a duplicate https://github.com/pnp/pnpjs/issues/726. The fix was already pushed.
This fix will be in the next release, which we might move up since folks are hitting this issue.
I downgraded to 1.3.2 and that has allowed me to proceed, I will be on the lookout for the new version when it is ready. Thanks for your help!
Closing this issue, fix will be release Friday July 12 as part of 1.3.4. Thanks!
Most helpful comment
I downgraded to 1.3.2 and that has allowed me to proceed, I will be on the lookout for the new version when it is ready. Thanks for your help!