How to upgrage SPFX version of the existed solution
In this post I will tell you how to upgrade the version of the SPFX framework of the existed solution. Here is the information only about SharePoint online, because for SharePoint 2019 On-premises you can use only NodeJs 10 and spfx 1.4.0.
To upgrade the version of the SPFX framework of the existed solution you need to follow the next steps.
Step 1. Commit your existing code to Git or just make a local backup!
Step 2. Install Microsoft 365 CLI. It will check your solution and creates a plan of the upgrade
Step 3. Open the root directory of the solution and to execute:
m365 spfx project upgrade --toVersion 1.21.1 --output md > upgrade.md
Step 4. View the report upgrade.md
Here you will find the steps for the upgrade - which packages to update and what to change in the configs.
Step 5. Update the packages and dedupe them
npm i -SE @microsoft/sp-core-library@1.21.1 @microsoft/sp-lodash-subset@1.21.1 @microsoft/sp-office-ui-fabric-core@1.21.1 @microsoft/sp-webpart-base@1.21.1 @microsoft/sp-property-pane@1.21.1 @microsoft/sp-component-base@1.21.1 @microsoft/sp-http@1.21.1 @microsoft/sp-adaptive-card-extension-base@1.21.1
npm i -DE @microsoft/sp-build-web@1.21.1 @microsoft/sp-module-interfaces@1.21.1 @microsoft/eslint-plugin-spfx@1.21.1 @microsoft/eslint-config-spfx@1.21.1 eslint@8.57.1 typescript@5.3.3 @microsoft/rush-stack-compiler-5.3@0.1.0
npm dedupe
Step 6. Modify files
6.a. './.yo-rc.json'
Update version in .yo-rc.json:
{
"@microsoft/generator-sharepoint": {
"version": "1.21.1"
}
}
6.b. ./tsconfig.json
Update tsconfig.json extends property:
{
"extends": "./node_modules/@microsoft/rush-stack-compiler-5.3/includes/tsconfig-web.json"
}
6.c. ./package.json
Update package.json engines.node property:
{
"engines": {
"node": ">=22.14.0 < 23.0.0"
}
}
After all these steps everything should work, but not always.
For example, once I had an error in app, because 2 different versions of @microsoft/rush-stack-compiler were in my package.json - 5.3 and 4.7. I removed the old one and left "@microsoft/rush-stack-compiler-5.3": "0.1.0".

Install Debian as a Windows Subsystem for Linux (WSL)