I found some articles which are explaining creating modern sites with CSOM. But I am not able to find in JavaScript to use in SPFx. Creating modern sites is supported with SPFx? Any PnP extension available for this?

up vote 7 down vote accepted

You can use the PnPJS to create modern team and communication sites.

For that, simply add the below packages:

npm install @pnp/logging @pnp/common @pnp/odata @pnp/sp --save

After that, you can add the below import statement:

import { sp } from "@pnp/sp";

And in the webpart, you can use it as below to create modern sites:

1) Modern communication sites:

sp.site.createCommunicationSite(
            "Comm Site Title",
            1033,
            true,
            "https://tenant.sharepoint.com/sites/commSite",
            ).then(d => {
                console.log(d);
            });

2) Modern team site:

sp.site.createModernTeamSite(
        "displayName",
        "alias",
        true,
        1033,
        "description",
        "",
        ["user1@tenant.onmicrosoft.com","user2@tenant.onmicrosoft.com","user3@tenant.onmicrosoft.com"])
        .then(d => {
            console.log(d);
        });

Reference - PnPJS Sites

  • 1
    I don't see the point to have two identical answers.. so deleted mine despite I answered a bit earlier than you... – Sergei Sergeev Dec 7 at 14:52

You can do that with the most recent version (1.2.6) of PnPjs library:

import { sp } from "@pnp/sp";

sp.site.createModernTeamSite(
        "displayName",
        "alias",
        true,
        1033,
        "description",
        "HBI",
        ["user1@tenant.onmicrosoft.com","user2@tenant.onmicrosoft.com","user3@tenant.onmicrosoft.com"])
        .then(d => {
            console.log(d);
        });

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.