JS SDK has a bug in which the deprecation error message from Az interferes with getting the token. So there are essentially 2 things to look out for -
Make sure any kind of warning message doesn't interfere with parsing and returning the access token
Update the az command to use the -SecureString flag for returning the access token.
Related issue - Azure/azure-sdk-for-js#30356