pnp / pnpjs

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs
https://pnp.github.io/pnpjs/
Other
753 stars 305 forks source link

Sharepoint fetching API not working after nodejs updated to version 18 #2969

Closed karthigamahe closed 4 months ago

karthigamahe commented 5 months ago

Major Version

3.x

Minor Version Number

1.0

Target environment

SharePoint Framework

Additional environment details

I am using nodejs and authenticated based on MSAL

Expected or Desired Behavior

I am trying to get the sharepoint folder structure to display in UI.

Observed Behavior

I am getting 500 internal server error in UI also in server i am getting this issue

_TypeError: Failed to parse URL from at .Request ( node:internal/deps/undici/undici:5272 ) at .mergeHeaders ( /layers/google.nodejs.yarn/yarn_modules/node_modules/@pnp/common-commonjs/net.js:9 ) at .SPHttpClient. ( /layers/google.nodejs.yarn/yarn_modules/node_modules/@pnp/sp-commonjs/sphttpclient.js:38 ) at .step ( /layers/google.nodejs.yarn/yarn_modules/node_modules/tslib/tslib.js:143 ) at .Object.next ( /layers/google.nodejs.yarn/yarn_modules/nodemodules/tslib/tslib.js:124 )

Steps to Reproduce

This is the code i am running to get the folders

async childFolders(entryPath: string): Promise<IFolderInfo[]> {
    let result: IFolderInfo[] = [];
    result = await sp.web.getFolderByServerRelativeUrl(entryPath).folders();
    if (entryPath == process.env.SP_PATH_PREFIX) {
      result = result.filter((o) => o.Name.trim().toLowerCase() == SP_ROOT_FOLDER);
    }
    return result;
  }

 async currentFolderDetail(currentFolderPath: string): Promise<IFolderInfo> {
    console.log('\n\n\n------ sp service currentFolderDetail -----\n\n\n\n',);

    return await sp.web.getFolderByServerRelativeUrl(currentFolderPath).folders();
  }

// sharepoint stuffs
  async getChildFolders(entryPath: string): Promise<ChildFolder[]> {
    console.log('\n\n\n------ getChildFolders -----\n\n\n\n',);

    const [children, father] = await Promise.all([
      this.spService.childFolders(entryPath),
      this.spService.currentFolderDetail(entryPath),
    ]);
    console.log("father.ServerRelativeUrl", father.ServerRelativeUrl)
    return children.map((x: IFolderInfo) => {
      return <ChildFolder>{
        FolderName: x.Name,
        ParentUniqueID: father.UniqueId,
        RootPath: father.ServerRelativeUrl,
        SharePointSite: `https://ts.accenture.com${father.ServerRelativeUrl}`,
        UniqueID: x.UniqueId,
        ID: randomInt(9999),
      };
    });
  }
juliemturner commented 5 months ago

To summarize I believe you're saying this worked fine in Node 16 but now that you're on Node 18 it doesn't work, is that correct? I might point you to this issue #2823.

patrick-rodgers commented 4 months ago

Closing this issue as answered. If you have additional questions or we did not answer your question, please open a new issue, ref this issue, and provide any additional details available. Thank you!

github-actions[bot] commented 4 months ago

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.