-So say the notes provided by M. Charlotte Wolf in the collection of Schonwerth tales, describing the folklore surrounding Jackolanterns in Bavaria. The collection includes this story:
75. Jack- o'-Lanterns
"A man from the village of Breitenwun near Velburg went home one night from the country fair, rather drunk. On the way, little lights were bobbing along before him, whereupon he called out to them, "If you give me light so that I may find my way home, I will give each of you a Taler [coin]."
Even more merrily the little lights bobbed along before him until the man reached his village. Then he said, "Now you can go home again; I don't need you anymore."-However, the little lights did not go home, but went in front of him, to his house, and from there into his sitting room, and they lighted the farmer's way to bed, and they kept glowing until he fell asleep. And so it happened every night; as soon as daylight faded, they were around him. Then he built a chapel in the village and paid for an eternal flame. As soon as it burned for the first time, the little lights were no longer seen. -The little chapel still stands today, but the eternal flame has gone out."
Arnold Bocklin, painting of will-o'-the-wisp
Versions of Jack-o'-Lantern tales are found all over Europe, but they are thought to originate with "the phenomenon of strange lights flickering over beat bogs", also known as will-o'-the-wisp, according to Wikipedia. You can read a different version from Ireland over at Fairy Tale Fandom.
Again from Wikipedia: "Jack-o-lanterns were also a way of protecting your home against the Undead. Superstitious people used them specifically to ward away vampires. They thought this because it was said that the Jack-o-lantern's light was a way of identifying vampires and, once their identity was known, they would give up their hunt for you."