How can I hide fields by user role when viewing a node?
OK, this code seems to be the solution:

/**
 * Implements hook_entity_field_access().
 */
function MYMODULE_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account, \Drupal\Core\Field\FieldItemListInterface $items = NULL) {
  if ($field_definition-&gt;getName() == 'NAME_OF_THE_FIELD' &amp;&amp; $operation == 'view') {
    return \Drupal\Core\Access\AccessResult::forbidden();
  }
  else {
    return \Drupal\Core\Access\AccessResult::neutral();
  }
}