spacer
Skip to content

@pnp/sp/features

Features module provides method to get the details of activated features. And to activate/deactivate features scoped at Site Collection and Web.

IFeatures

Invokable Banner Selective Imports Banner

Represents a collection of features. SharePoint Sites and Webs will have a collection of features

Scenario Import Statement
Selective 1 import { sp } from "@pnp/sp";
import "@pnp/sp/features/site";
Selective 2 import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/features/web";
Selective 3 import { sp } from "@pnp/sp";
import "@pnp/sp/features";
Selective 4 import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/features";
Preset: All import { sp, IFeatures, Features } from "@pnp/sp/presets/all";

getById

Gets the information about a feature for the given GUID

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

//Example of GUID format a7a2793e-67cd-4dc1-9fd0-43f61581207a
const webFeatureId = "guid-of-web-feature";
const webFeature = await sp.web.features.getById(webFeatureId)();

const siteFeatureId = "guid-of-site-scope-feature";
const siteFeature = await sp.site.features.getById(siteFeatureId)();

add

Adds (activates) a feature at the Site or Web level

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

//Example of GUID format a7a2793e-67cd-4dc1-9fd0-43f61581207a
const webFeatureId = "guid-of-web-feature";
let res = await sp.web.features.add(webFeatureId);
// Activate with force
res = await sp.web.features.add(webFeatureId, true);

remove

Removes and deactivates the specified feature from the SharePoint Site or Web

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

//Example of GUID format a7a2793e-67cd-4dc1-9fd0-43f61581207a
const webFeatureId = "guid-of-web-feature";
let res = await sp.web.features.remove(webFeatureId);
// Deactivate with force
res = await sp.web.features.remove(webFeatureId, true);

IFeature

Represents an instance of a SharePoint feature.

Invokable Banner Selective Imports Banner

Scenario Import Statement
Selective 1 import { sp } from "@pnp/sp";
import "@pnp/sp/features/site";
Selective 2 import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/features/web";
Selective 3 import { sp } from "@pnp/sp";
import "@pnp/sp/features";
Selective 4 import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/features";
Preset: All import { sp, IFeatures, Features, IFeature, Feature } from "@pnp/sp/presets/all";

deactivate

Deactivates the specified feature from the SharePoint Site or Web

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

//Example of GUID format a7a2793e-67cd-4dc1-9fd0-43f61581207a
const webFeatureId = "guid-of-web-feature";
sp.web.features.getById(webFeatureId).deactivate()

// Deactivate with force
sp.web.features.getById(webFeatureId).deactivate(true)