Those ghosts enemies are invisible, not invincible, by shooting at the position from which the ghost fires, you can kill them, fortunately only ranged enemies can become ghosts.
Also in the wetlands levels, where enemies are the most likely to become ghosts, the floor is covered in water, which gets disturbed when the player and most enemies move, making it easier to figure out where to aim at, and the only flying enemy shoots constantly behind itself when moving, which gives away its position.