WebGL build Failed! Unity 2021.3.21f

I try to create a build for WebGL and it keeps failing and it pops up the following error message.
Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\Raycasters\Physics2DRaycaster.cs(106,38): error CS0117: ‘SortingGroup’ does not contain a definition for ‘GetSortingGroupByIndex’

Help Needed!

I just had the same issue on a blank project. Closing all editors, reinstalling the editor from Unity hub fixed the issue for me.