SPFx Environment Setup Step By Step Guide – 2024

You can only use the SharePoint framework to do custom development for a modern SharePoint Online site.

To develop using the SPFx framework, you must first set up the environment. This includes installing all the necessary tools, such as a code editor, Node.js, Gulp, Yeoman, and the Yeoman SharePoint generator.

I will also show you how to develop your first spfx client-side web part using the SharePoint Framework. Finally, I will tell you how to deploy an SPFx web part to a SharePoint site and add it to a SharePoint site page.

What is the SharePoint Framework (SPFx)?

The SharePoint Framework (SPFx) is a development model for building and customizing user interfaces in SharePoint. It allows developers to create web parts, extensions, custom pages, team tabs, and web components for use in SharePoint sites.

SPFx uses modern web technologies like TypeScript, React, and Node.js, enabling developers to create responsive and dynamic user experiences. It’s designed to work seamlessly with various Microsoft 365 applications and SharePoint Online.

SPFx Development Environment Set up

The SPFx environment setup is a one-time activity you need to do before developing any SPFx components.

First, we must install all the necessary tools for developing an SPFx project.

Install a code editor

You need a code editor to write your SPFx code. You can install any code editor or IDE that supports client-side development, like:

I highly recommend downloading Visual Studio Code because it’s free, cross-platform, and highly customizable.

Install Node.js

We download Node.js because it provides the JavaScript runtime environment necessary to run tools and scripts for developing SharePoint Framework (SPFx) projects. Node.js also includes npm (Node Package Manager), which is used to install and manage dependencies for your SPFx project.

Recommended Version: The LTS (Long Term Support) version of Node.js 18v is recommended for SPFx development. You must always follow the Microsoft SPFx setup guide to know which version of Node.js is supported for SPFx.

1. Installing Node.js is straightforward. Just double-click on the setup file. Then click the Next button.

2. Accept the license agreement, choose your download location, and click ‘Next.’ Do not change any settings and click ‘Next‘ again.

sharepoint development environment

3. Then check the automatically install the necessary tools check box and click Next.

learn spfx development step by step

4. Click on the ‘Install‘ button. After some time, the ‘Successfully Installed’ page will appear. Then, click ‘Finish.’

setup sharepoint framework environment

5. After that, the Node.js command prompt will automatically open to download the additional tools here; you can press any key to start downloading.

spfx step by step

6. After completing the download, open the Node.js command prompt and check the node version using the below command.

node -v
or
node --version

It will show the node version as V18…

sharepoint framework

Install development toolchain prerequisites

Open the Node.js command prompt in admin mode, then install the below tools.

Install Gulp

Then, we installed Gulp because it is a task runner that helps automate and manage repetitive development tasks in SPFx projects.

Enter the following command in the Node.js command prompt to install the Gulp:

npm install gulp-cli --global
spfx setup

Install Yeoman

Then, we installed Yeoman because it helps generate the project structure and boilerplate code needed for SPFx development.

Enter the following command to install Yeoman:

npm install yo --global
setup spfx environment

Install Yeoman SharePoint generator

Now, let’s install the Yeoman SharePoint generator. This tool helps create a SharePoint client-side solution project with the correct toolchain and project structure.

To install the SharePoint Framework Yeoman generator globally, use the following command:

npm install @microsoft/generator-sharepoint --global
sharepoint framework development consultant

Alternatively, you can also run all the above commands in a single line

npm install gulp-cli yo @microsoft/generator-sharepoint --global

Then, one more important step is pending before the setup is completed.

We need to run the below command ONLY ONCE after you create your first project in the project’s root folder.

gulp trust-dev-cert

So, let us create an SPFx client-side web part.

Create a New Client Side Web Part Project

Now follow the below steps to create a new web part project:

Open the Node.js command prompt and create a folder by using the below command:

  • cd.. = This moves you up one directory.
  • md foldername = This creates a new folder named “foldername.”
  • dir = This shows you a list of files and folders in the current directory.
  • cd foldername = This moves you into the newly created folder.

I hope you create a folder using the command prompt.

spfx examples

To create a new web part project, run the Yeoman SharePoint Generator from within the new folder using the following command:

yo @microsoft/sharepoint

The above command will create the SharePoint client-side solution project structure. You will see a welcome message with a question like this:

sharepoint spfx examples

For all questions, accept the default options except for the following questions:

  • What is the solution name?NewWebPart
  • Which type of client-side component to create?: WebPart
  • What is your Web part name?: NewWebPart
  • Which template would you like to use?: No framework
spfx samples

Now, it will create and import all the files into the folder we created. Setting up the SharePoint Framework client web part will take some time. It will look like this:

spfx webparts

If the first time you are developing the client-side web part in spfx, then run the below command once.

gulp trust-dev-cert

Note: You do not need to run the command for all the web parts; it needs to be executed just once.

spfx web part

Start the local web server & launch the hosted workbench

Then, to run the web part in your local host, put the below command:

gulp serve
sharepoint web part examples

This command runs gulp tasks to create and start a local web server hosting endpoints at localhost:4321 and localhost:5432. It will then open your default browser and load the hosted workbench to preview web parts from your local dev environment.

Here, we need to give our SharePoint tenant name.

spfx webpart

The SharePoint Workbench is a developer design surface that allows us to quickly preview and test web parts without deploying them to SharePoint.

sharepoint web part development

To add the newly created web part, select the add icon. This opens the toolbox, where you can see the list of web parts available to add. Now, select the NewWebPart.

create spfx webpart

Then it will look like the below screenshot.

create spfx webpart using react step by step

At this point, we successfully created the web part using SPFx.

Click the pencil icon, then modify the text in the ‘Description’ text box on the right side. Notice how the text in the web part changes as you type.

deploy spfx webpart to sharepoint online

In the Node.js command prompt, click ctrl + c to stop the local web server by terminating the process.

Then it will look like this:

sharepoint spfx web part examples

Enter the following command to open the web part project in VS Code (or use your favorite editor):

code .
spfx webpart examples

Deploy our SPFx Web Part to a SharePoint Online Site

Next, you can deploy the web part into a SharePoint Online site.

Package the web part

Now, in the code editor, open the terminal and run the following command:

gulp bundle

 Then, enter the below command to package the web part that we created :

gulp package-solution

This command creates a package where our web part store we need to put in the SharePoint site app catalog.

To see this file, go to sharepoint/solution/new-web-part.sppkg in the VS Code.

microsoft sharepoint client web

To view the file in File Explorer, right-click the file and select ‘Reveal in File Explorer.’

sharepoint workbench

Deploy the Web Part Package to the Site Collection App Catalog

Here, I want to deploy the web part in the Site Collection App Catalog, not the Tenant App Catalog.

Note: If you want to deploy the SPFx web part to the organizational app catalog, you can upload it to the organization’s app catalog site.

1. To enable the Site Collection App Catalog, use the following PowerShell script:

Connect-SPOService -Url https://<tenant>-admin.sharepoint.com/ -Credential MiriamG@<tenant>.onmicrosoft.com
$site = Get-SPOSite https://<tenant>.sharepoint.com/sites/SPFx

Add-SPOSiteCollectionAppCatalog -Site $site
add custom web part to sharepoint online

If you want to disable the Site Collection App Catalog, use the script below:

Remove-SPOSiteCollectionAppCatalog -Site $site

2. When you navigate to the Site contents where you enabled the Site Collection App Catalog, you’ll see a new list called “Apps for SharePoint.” Here, you need to deploy your web part package.

build spfx webpart

3. Open the Apps for SharePoint list and upload or drag and drop the .sppkg file.

sharepoint framework examples

4. Then, a popup window will open, where you need to click “Deploy.” You can check the checkbox to show the web part to all sites in the organization.

sharepoint workbench url

5. Go to the Home page, click +New, then select App.

spfx deployment steps

6. To add the SharePoint Framework client web part to the SharePoint site, click the “Add” button.

spfx sample webparts

7. When you revisit the Site Contents, you’ll find the web part app listed there.

sharepoint webpart

Add the Web Part to the Modern SharePoint Page

1. Navigate to your site where the solution was installed. Edit the page, open the web part picker, and select our web part.

sharepoint online custom web parts

2. Click on the web part to add it to the SharePoint Online modern page.

sharepoint custom web part

This is how to set up your development environment for the SharePoint framework. I have shown you all the steps with screenshots. I have also shown how to create your first SharePoint client-side web part using SPFx.

Finally, I explained how to deploy a client-side web part to a SharePoint site app catalog and then add the web part to a site page.

You may like the following SPFx tutorials:

  • I have created spfx environment in my laptop and now shareing complete complete code files through one drive to my colleague. Now please tell me how to setup environment with existing code in my colleague’s laptop

  • I have followed all the steps and it is working fine but after adding the webpart on sharepoint page, I am getting

    Something went wrong
    If the problem persists, contact the site administrator and give them the information in Technical Details.
    TECHNICAL DETAILS
    ERROR:
    Script error for: 5e53f0dc-de0c-4224-aeb0-f27fe39e7654_0.0.1/NewWebPartWebPartStrings
    http://requirejs.org/docs/errors.html#scripterror

    CALL STACK:
    Error: Script error for: 5e53f0dc-de0c-4224-aeb0-f27fe39e7654_0.0.1/NewWebPartWebPartStrings
    http://requirejs.org/docs/errors.html#scripterror
    at B (eval at e (https://res-1.cdn.office.net/files/sp-client/sp-pages-assembly_en-us_76321800eff580162db09111ef3c3533.js:198:10299), :8:252)
    at HTMLScriptElement.onScriptError (eval at e (https://res-1.cdn.office.net/files/sp-client/sp-pages-assembly_en-us_76321800eff580162db09111ef3c3533.js:198:10299), :30:244)

  • >