There is on this site already a question and answer that take a pretty comprehensive look at the difficulties this verse presents. However they do not, to my mind, really focus on the word "jealously" as it occurs here in James 4:5.
There are two Greek words, zeloute and phthonon, which are commonly translated "envy". phthonon occurs nine times in the N.T.
Mt 27:18 envy bad sense - wanting Jesus' power [?]
Mk 15:10 envy bad sense -to glory before the people,not desiring to be like Jesus for His sake [?]
Ro 1:29 envy bad sense associated with murder, strife and evil in many forms.
Ga 5:21 associated with evil in many forms.
Phl 1:15 a. with evil in many forms.
1 Tim 6:4 a. with evil.
3:3 Tit a. with evil.
James 4:5 under consideration.
1 Peter 2:1 "put away all malice and deceit and hypocrisy and envy" bad sense.
However zelos 6 examples:
Acts 17:5 bad envy, jealousy, "wicked men".
1 Cor 12:31 good envy, earnestly desire, want the higher gifts.
1 Cor 13:4 bad envy, love does not envy.
2 Cor 11:2 good divine jealously, a desire for the best.
Ga 4:17 zelos, "for no good purpose" bad sense.
Ga 4:18 zelos "for a good purpose" good sense.
We see here that phthonon is never in a good sense, so far. But zelos is freely able to be in the good or bad sense.
We can also note that James uses both of these words in close proximity to each other in Ch 4. 4:2 "You zeloute and cannot obtain".
I suggest that in ch 4 James has just used zelos [v2] but chooses not to use it again in v5 because he wants a word that is unambiguously only ever associated with envy in its evil sense.
The E.S.V. goes against what I have laid out here by saying, He, God, does do phthonon. "He yearns jealously/phthonon".
How might the E.S.V. justify such a position? In this sense what does "jealously" mean in James 4:5?