dnd 5e – Can a barbarian maintain rage by attacking a creature that is not present?

RAW, no. Rage is constrained by the rules of the game, not in-universe reasoning

On the supremacy of the rules:

Combat is a distinct phase of the game and is different from non-combat. Tables vary, but most I’ve heard of treat out-of-combat time very loosely, don’t worry about movement speed, turn order, or anything like that. When that state changes and combat begins, an initiative roll is called.

This gives meta-information to players– even if a PC isn’t aware that combat is underway when the roll is called, the player definitely knows.

Similarly, things that we know would work in the real world, like electrifying a body of water or a fire not starting while submerged in water, don’t happen in D&D. Not because we have no reason to think that they would work, but because it’s a game and not a reality simulator. So right there we can answer the question of why Rage is limited by the reality of the situation rather than the Barbarian’s belief: the rules exist, and they don’t say anything about the Barbarian’s belief.

Applicable rules in this situation:

While a character can usually attack anything, there are mechanical limitations on that action. For example, a character using a shortbow can attack an enemy that is 320 feet away or closer, but not farther:

You can’t attack a target beyond the weapon’s long range. (PHB, Chapter 5, Weapons, Weapon Properties)

The character could still fire the bow in that direction, but could not attack an enemy outside of the weapon’s long range. This is strictly a mechanical, rules-based issue because it depends on the rules’ definition of an attack.

Similarly, you can’t attack an enemy that isn’t there. You could swing a weapon around with the intention of hitting such an enemy, but the Attack action has a direct object (the target). It’s not as great of a koan as the famous version, but a tree that doesn’t exist doesn’t make a sound whether it falls or not, regardless of the presence of any observer. The sentence itself doesn’t even parse properly– there is no tree to fall or not fall, nor any place for that non-thing to be.

In chess, a pawn can’t move backwards no matter how helpful it might be to do so in a given situation. A real foot soldier can easily move backwards, but chess is governed by different rules than real soldiers. In the same way, a Barbarian can’t attack an enemy that isn’t there.

A sensible ruling:

There are plenty of edge cases where applying this rule directly is odd, such as a combat in which the Barbarian’s intended target flees (and leaves combat) while other enemies are still present. But I submit that, because Rage itself depends on the rules-defined mechanical construct of combat, it doesn’t make sense to consider Rage independent of that construct.

If combat is still happening it may be easier, more narratively interesting, and more fun to allow the Barbarian to maintain Rage while attacking the enemy, generically: Barbarhianna wants to attack Chad the cultist, who has hidden and fled from combat and so cannot be validly targeted no matter what. But if cultists Alan, Betsy, and Dylan are still around and fighting I as DM would probably allow Barbarhianna’s attack, intending to hit Chad, to maintain Rage.

But that’s my preference as DM. The rules being written or designed awkwardly does not impose new rules not written anywhere on the game. That portion of the ability is defined by a potentially valid target, and so if there is no valid target to attack Rage cannot be maintained via that mechanism.