我在 VS 中使用以下代码。(我参考了这篇文章https://www.agrenpoint.com/azurefunction-v2-pnpjs/)
但它说不支持 ES 模块的 require()。
如何解决这个问题??
// 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"
};
}
};