Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

361
Views
require() of ES Module not supported

I am using the below code in VS. ( I referred this article https://www.agrenpoint.com/azurefunction-v2-pnpjs/ )

But it says require() of ES Module not supported.

How to resolve this issue ??

// equal to: import { sp } from "@pnp/sp;"
const sp =  require("@pnp/sp").sp;

// equal to: import { SPFetchClient } from "@pnp/nodejs;"
const SPFetchClient = require("@pnp/nodejs").SPFetchClient;

module.exports = async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    if (req.query.site || (req.body && req.body.site)) {
        const siteName = req.query.site || req.body.site;
        sp.setup({
            sp: {
                fetchClientFactory: () => {
                    return new SPFetchClient(
                      `${process.env.spTenantUrl}/sites/${siteName}/`, 
                      process.env.spId, 
                      process.env.spSecret);
                },
            },
        });

        // Get the web and all the Lists
        const web = await sp.web.select("Title").expand('Lists').get();

        context.res = {
            // status: 200, /* Defaults to 200 */
            body: "All of the lists in the site " + web.Title + ": " + web.Lists.map(list => list.Title).join(', ')
        };
    }
    else {
        context.res = {
            status: 400,
            body: "Please pass a site on the query string or in the request body"
        };
    }
};
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!