OK, here’s a quick one for today…
Microsoft doesn’t seem to discuss developing SharePoint Framework with WSL2. So far I haven’t had any issues with it, so it seems about time to discuss it.
SharePoint Framework requires NodeJS 10.x. In fact, it won’t work on a more recent Node version. On my Windows 10 machine I’m running a later release. Ubuntu on WSL allows me to manage my NodeJS versions with Node Version Manager . With this I can have multiple Node versions installed and can alternate between them. I just need to remember to ensure which Node version I’m running before I start work.
First of all, some assumptions… I’m assuming you have the already have the following set up:
nvm install --lts=dubnium) and have switched to it (nvm use lts/dubnium)npm install -g yo @microsoft/generator-sharepoint)gulp serve as you do when Gulp is installed globally, you can type npx gulp serve or add it to a start script in your package.json and type npm start. I recommend the latter.The Yeoman SPFx generator pretty much works as normal with this one caveat.
There is an instruction to run gulp trust-dev-cert. On Windows 10, this adds a self-signed certificate into your Certificate Store. Running this from WSL2 won’t work.
The self-signed certificate will be found in ~/.gcb-serve-data. You need this to run the local workbench.
$wsl/Ubuntu-20.04/home/ubuntu/.gcb-serve-data (I’m using Ubuntu 20.04 on WSL2. If you’re using something different, browse to that instead)So far, it’s working fine for me. The only issue I had was forgetting to ensure my Node version before compiling. I ended up with a nasty and confusing looking build error while still using Node 12 LTS. So be sure you’re running Node 10 by typing node --version.