Alternative ways to programmatically add user fields?
I found a solution using .yml files in your modules config/install directory.

1. Create the user field 

go to Configuration -> People -> Account Settings -> Manage fields and press "+ Add field". I'd recommend giving the field a unique machine-readable name to prevent conflicting user fields.



Enable the user field in Manage Form Display and Manage Display if you want it to appear in the users edit profile and registration page.

2.Exporting the user field configuration

go to Configuration -> Development -> Configuration Synchronization -> Export -> Single Item

Once you get to a screen similar to the one below, set configuration type to "Field" then set the configuration name to the field you have created.

In your modules Config/install folder(create one if needed) create a new file named after filename highlighted in red below.

Finally Copy the yml text into the file you just created.



then set configuration type to "Field Storage" then set the configuration name to the user field you have created.

In your modules Config/install folder(create one if needed) create a new file named after filename highlighted in red below (don't copy the one in the example your user field will have a different name).

Finally Copy the yml text into the file you just created.



YOU NEED BOTH YML FILES TO PROGRAMMATICALLY CREATE A USER FIELD

I recommend doing this for each user field you want to programmatically add rather than copying the configuration and changing a few properties.

With this method you can uninstall the module that created these user fields.