Suppose a raging barbarian cannot reach any seen opponents on the battlefield on their current turn, but is attempting to maintain rage in the interim by attacking a hostile creature, according to the following:
Your rage lasts for 1 minute. It ends early if you are knocked unconscious or if your turn ends and you haven't attacked a hostile creature since your last turn or taken damage since then.
Suppose the player is making a good-faith attempt to maintain rage because they are still in combat, just unable to reach visible opponents within one round.
The barbarian declares an attack on a hostile creature they suspect is within their reach but which they cannot see.
If there was a successfully hidden opponent on the field, then RAW the barbarian would be permitted to attack it by guessing its location. Even if they were incorrect about the target's location, that would be sufficient to maintain their rage. We know that attacking near a present target is allowed, and the barbarian needs no surety that the creature is actually in the location guessed.
But if the successfully hidden opponent has actually left the field without the barbarian knowing, there is not a creature to attack.
Is the barbarian permitted to make an attack against an opponent that is not present?
I am trying to understand whether a creature actually needs to be present for the barbarian to attack, and if so, why its presence matters, or matters more than the barbarian's intent.
To me, either ruling, yes or no, has unfortunate implications.
If attempting to attack an opponent that is not on the field ends the barbarian's rage, that allows rage to be used as an 'enemy presence detector', which seems to go against the spirit of "If the target isn't in the location you targeted, you automatically miss, but the DM typically just says that the attack missed, not whether you guessed the target's location correctly."
But if the barbarian is allowed to maintain rage by attacking an opponent that is not actually there based on the plausible belief that an opponent is present, then what prevents the barbarian from postulating an opponent who could be there? For example, the barbarian invokes an NPC that has successfully hidden against the party before. The barbarian's belief that said NPC is present and Hidden can then become a source of conflict between the player and the DM, in trying to decide what is a reasonably imagined unseen opponent.
I am not asking about a bad faith attempt by a player to invent opponents that don't exist.
Somewhat related: A barbarian's belief that they are attacking an opponent is apparently not sufficient to maintain rage if what they are attacking is an illusion. So attacking a not-creature that is there is not enough to maintain rage, but is it enough to attack an actual creature that is not there?