This happens if I take too much melatonin. The dosage in US-sold melatonin is unnecessarily high. Finnish tablets are typically 1.9mg, while US ones can have 10mg in just one.
Luckily some people warned about this a lot online (not to take too much, most pills are too much) and I was able to find 1mg tablets on Amazon when I wanted some.
I take melatonin (0.2mg via a spray). It is very effective. Nightmares are a recurring problem for me and other users I know, but can be solved with low doses and a lot of discipline.