I tested the above code using the Ballerina latest release 2201.12.0. It compiled without any errors.
2201.12.0
Please do the following steps and compile it again
Remove Dependencies.toml file
Dependencies.toml
Run bal clean
bal clean
Run bal run
bal run