Fixing SPFx: Unable to Use the Latest Version in scaffolding project
Introduction
The SharePoint Framework (SPFx) 1.20.0 has been generally available since September 2024. However, if you work with SPFx, you might encounter issues when trying to use the latest version. SPFx still requires Node.js 18.x.x. In this blog post, I’ll walk you through the steps I took to install Node.js 18.20.4 using NVM, install the SPFx toolchain, and troubleshoot an issue where the project scaffolding defaulted to an older version of SPFx.
Step-by-Step Guide
1. Install Node.js
First, ensure you have NVM (Node Version Manager) installed on your machine. Then, install Node.js version 18.20.4.
nvm i 18.20.4
2. Install SPFx toolchain
Next, install the SPFx toolchain globally using npm.
npm install gulp-cli yo @microsoft/generator-sharepoint --global
3. Check SPFx version
Verify the installed SPFx to ensure they are the latest.
npm ls --depth 0 -g
4. Scaffold project issue
Despite ensuring that I was using the correct node.js version (18.20.4) and verifying the @microsoft/generator-sharepoint
was version 1.20.0 , the project scaffolding defaulted to version 1.18.2.
5. Troubleshooting and fix
I initially tried uninstalling earlier versions of Node.js from NVM, leaving only version 18.20.4, and even uninstalled and reinstalled NVM. However, the issue persisted.
After hours of troubleshooting, I decided to search for any instances of the generator-sharepoint
folder on my c: drive. I found an older version of the node_modules
directory in C:\Users\xxx
from February 2024. Deleting this directory resolved the issue, and the correct version of SPFx was used.
Conclusion
If you encounter issues with SPFx defaulting to an older version despite installing the latest version, check for any lingering node_modules
directories that might contain outdated versions of generator-sharepoint
. Deleting these directories can resolve the issue and ensure that your project scaffolds with the correct version of SPFx.