
Building robust and secure solutions in SharePoint Framework (SPFx) requires staying current with the latest version. But how do you know which version you’re using? This blog will guide you through two easy methods to check your SPFx version, along with a real-world example explaining why keeping things updated is crucial.
Here is how you can check what version of the SharePoint Framework (SPFx) you are using
Method 1: Using the package.json
File
- Open your SPFx project folder in your preferred code editor.
- Locate the package.json file. This file contains information about your project’s dependencies.
- Search for the
@microsoft/sp-core-library
dependency. The version number next to it indicates your current SPFx version.
Method 2: Using the Command Line
- Open a command prompt window and navigate to your SPFx project folder.
- Run the following command:
npm list @microsoft/generator-sharepoint
(without quotes) - The output will display the version information for the
@microsoft/generator-sharepoint
package, which reflects your SPFx version.
{
"name": "my-spfx-project",
"version": "1.0.0",
"dependencies": {
"@microsoft/sp-core-library": "^1.15.0" // This line indicates SPFx version 1.15.0 or higher
}
}
Why would you care
- Before creating a project – There are different versions of the SharePoint Framework (SPFx) available for various SharePoint environments. SharePoint Online supports all SPFx versions, with the latest offering the most features and capabilities. SharePoint 2019 supports SPFx up to v1.4.1, while SharePoint 2016 supports SPFx up to v1.1.0.
- Once you have a project – It’s uncommon to complete a project on day one and only need to fill in code afterward. As projects evolve, requirements change, and additional web parts and extensions may be needed. To prevent issues, use the SharePoint Framework Yeoman generator that matches your SPFx version. Using a different version can cause compatibility problems and waste time. To avoid this, install the SPFx Yeoman generator as a dev dependency in your project.
- Once you have a package – When deploying a SharePoint Framework solution to production, first ensure the package is supported in your SharePoint environment. For SharePoint Online, any SPFx version works, but it’s wise to check if a recent version is used for easier support. For SharePoint on-premises, ensure the package matches your server’s SPFx version. Deploying a package built with a newer version can cause deployment errors and waste time. Verify the SPFx version of the package before deployment to avoid issues.