This question asks what happens when a single-target spell has an invalid target. (A target that is not legitimately permissible, not a target that is weak from illness or injury).
The answer appears to be: that depends on whether one wishes to implement an older Sage Advice segment of a Dragon Talk podcast, or the more recent but optional written rules in Xanathar’s Guide to Everything.
Assume for this question that I prefer XGtE.
The rule for resolving invalid spell targets states (XGtE 85-86):
If you cast a spell on someone or something that can’t be affected by the spell, nothing happens to that target, but if you used a spell slot to cast the spell, the slot is still expended.
Now consider the chain lightning spell, in which
You create a bolt of lightning that arcs toward a target of your choice that you can see within range. Three bolts then leap from that target to as many as three other targets, each of which must be within 30 feet of the first target. A target can be a creature or an object and can be targeted by only one of the bolts.
Suppose my primary target for the spell is invalid, because it is not a creature or an object. If an example must be given, suppose it is an illusion. However, each of the three secondary targets of the spell are valid, being either creatures or objects.
Do I spend the spell slot with nothing happening at all, or does the slot get spent, the chain lightning impact the illusion but do nothing to it and then leap to the three valid targets with the full effects given in the spell description?
Note: I am assuming that an illusion is not an object, based largely on my interpretation that an illusion is not an "item" and on the text of the 14th-level School of Illusion wizard feature, Illusory Reality. I am open to frame challenges that demonstrate that illusions are, in fact, objects, but such answers will be better if they then either provide a more appropriate example of something that is not a creature or an object, or demonstrate that the question is moot since everything is at least either a creature or an object.