Pnpjs: Getting Error [ERR_REQUIRE_ESM]: Must use import to load ES Module, when importing "@pnp/sp/webs"

Created on 23 Oct 2020  路  9Comments  路  Source: pnp/pnpjs

Category

  • [ ] Enhancement
  • [X] Bug
  • [ ] Question
  • [ ] Documentation gap/issue

Version

Latest PnP version installed
Node: v12.19.0

Expected / Desired Behavior / Question

Expected behaviour will be that it works as asspected and as shown in pnp node samples.

Observed Behavior

Getting Error when i try to import "@pnp/sp/webs" and import "@pnp/sp/lists" into my .ts file.
This is a simple node server REST Api solution, you can check the code for this solution on [GitHub]
(https://github.com/gonadn/nodepnptest)

image

Error Message:
image

Steps to Reproduce

Clone the GitHub repo solution and "npm run dev"
image

documentation details needed question

Most helpful comment

All 9 comments

the error went away after using @pnp/sp-commonjs and @pnp/nodejs-commonjs, but i got another error when i try to get item from a list.
image

I hae the clientId and secret, and every thing should be correct.

i fixed the error: UnhandledPromiseRejectionWarning: Error: Error making HttpClient request in queryable [401] Unauthorized
i had to add cath like showing in code below:

sp.web.lists.getByTitle("TestList").items.get() .then((items: any) => { if (items !== null && items !== undefined) { resolve(JSON.stringify(items)); } else { reject("Error"); } }) .catch((error) => { reject(error); });

But know nothing happens, no error thrown. i tried with getting only web infor Title and description, and tems from a list. nothing works.

@gonadn,

New tenants by default block AddIn-Only auth for some time now.

If the custom app auth is disabled, it can be enabled with the following command:

set-spotenant -DisableCustomAppAuthentication $false

@koltyakov thanks for the response, but when running Powershell command set-spotenant -DisableCustomAppAuthentication $false i get an error.
image

And on microsoft documents https://docs.microsoft.com/en-us/powershell/module/sharepoint-online/set-spotenant?view=sharepoint-ps

I can not find the property: 'DisableCustomAppAuthentication'.

Any clue or other workaround ?

Installed SPO PowerShell version might require an update.

@koltyakov thanks alot, finally it worked. something wrong with PS on my machine, but i manged to fix it. Just one more question, will it be any issue when i deploy my app to Microsoft Store, and the app is using PnP libraries, will those who by or download the app have to do the same ?

@gonadn, the auth methods, and corresponding infrastructure depend on a solution. The library doesn't have opinions on which auth to use when in how. For provider-hosted apps, I'd suggest https://pnp.github.io/pnpjs/nodejs/provider-hosted-app/ wiring up. Unfortunately, I have no provider-hosted app to check will it work with disabled custom app authentication.

Going to close this.

Was this page helpful?
0 / 5 - 0 ratings