pnp / pnpjs

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

Property 'web' does not exist on type 'SPFI'. #2986

Closed jduysen closed 3 months ago

jduysen commented 3 months ago

What version of PnPjs library you are using

3.x

Minor Version Number

24

Target environment

NodeJS

Additional environment details

I am using Node.js with Typescript and MSAL for authentication.

Question/Request

So I am able to authenticate without issue and if I add //@ts-ignore above let lists = sp.web.lists() It executes without issue (I get the list information back. But I am getting an IntelliSense error on 'web' that states 'Property 'web' does not exist on type 'SPFI'.'

image

I am using the follow import, (but have also tried individual imports for web, lists, item, etc.): import '@pnp/sp/presets/all.js'

Here is my code for creating the spfi object:

import { spfi, SPFI } from "@pnp/sp/index.js";

export async function getSp(context, request, cert) {

  const clientId = process.env.CLIENT_ID;
  const tenantId = process.env.TENANT_ID;
  const config = {
    auth: {
      authority: `https://login.microsoftonline.com/${tenantId}/`,
      clientId: clientId,
      clientCertificate: {
        thumbprint: process.env.CERT_THUMBPRINT,
        privateKey: cert,
      },
    },
  };
  const sp:SPFI = spfi(process.env.SITE_URL).using(
    SPDefault({
      baseUrl: process.env.SITE_URL,
      msal: {
        config: config,
        scopes: ["https://tsbg0.sharepoint.com/.default"],
      },
    })
  )

  return sp
}

Any idea what I can do to get the correct IntelliSense for the library?

patrick-rodgers commented 3 months ago

One dumb idea, close and reopen vscode, that does sometimes help.

Slightly smarter idea, are you including the import statement in the same file you show the code or another file? If the import of that location is indirect sometimes the types aren't resolved correctly. We could also have an issue with the typings coming out of the preset but I thought that was working. Can you share your tsconfig.json?

jduysen commented 3 months ago

Thanks for the quick reply. I have tried putting the import into the file containing my getSp function but that issues the same error. Here is my tsconfig.json:

{
  "compilerOptions": {
    "module": "NodeNext",
    "target": "es6",
    "outDir": "dist",
    "rootDir": ".",
    "sourceMap": true,
    "strict": false,
    "moduleResolution": "NodeNext"
  }
}
jduysen commented 3 months ago

So I looked at your example and changed my tsconfig to match yours and it works now. Thanks for pointing me in the right direction.

{
  "compilerOptions": {
    "module": "ESNext",
    "target": "es6",
    "outDir": "dist",
    "rootDir": ".",
    "sourceMap": true,
    "strict": false,
    "moduleResolution": "Node"
  }
}
github-actions[bot] commented 3 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.