sharepoint online – Create a modern team site in SPFx

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

For that, simply add the following packages:

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

After that, you can add the following import declaration:

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

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

1) Modern communication sites:

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

2) Modern equipment site:

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

Reference – PnPJS Sites