Josselyn wrote several books describing what he saw in New England, including strange animals, Native American customs, and unusual plants. Among those plants was the following:
Cran Berry or Bear Berry, because bears use much to feed upon them, is a small trailing plant that grows in salt marshes that are overgrown with moss. The tender branches (which are reddish) run out in great length, lying flat on the ground, where at distances, they take root, over-spreading sometimes half a score acres, sometimes in small patches of about a rod or the like...
The berries, hanging by a small root stalk, no bigger than a hair; at first they are of a pale yellow color, afterwards red and as big as a cherry; some perfectly round, others oval, all of them hollow, of a sour astringent taste. They are are ripe in August and September...
The Indians and English use them much, boiling them with sugar for sauce to eat with their meat. And it is a delicate sauce, especially for roasted mutton. Some make tarts with them as with goose berries. (John Josselyn, New-England's Rarities Discovered, 1671)
And that, as far as I can tell, is the first written mention of cranberry sauce*. Somewhere between 1638 and the 1660s people were already using cranberries, a native North American fruit, to make what is now a classic Thanksgiving dish.
Before the English came the local Indians used cranberries in a dish called pemmican, which was made of dried meat, berries, and animal fat. When the English arrived they used cranberries in traditional British dishes. Cranberry sauce was the New England version of a traditional English barberry conserve, barberry being a sour fruit that grew in Europe. Here's a recipe from 1597:
To make a conserve of barberrries
Take your barberries and pick the clear, and set them over a soft fire, and put to them rosewater as much as you think good. Then, when you think it be sod enough, strain that, and then seethe it again, and to every pound of barberries, one pound of sugar, and meat your conserve. (Thomas Dawson, Second Part of the Good Housewives Jewel, 1597, quoted in James Baker's Thanksgiving. The Biography of an American Holiday, 2009)
At first that seemed like a pretty high sugar to berry ratio to me, but looking at some modern cranberry sauce recipes online I found it's really not. Most modern recipes call for one cup of sugar per twelve ounce bag of berries. A pound of sugar is just under two cups, and a pound is sixteen ounces. So really this old barberry conserve is a little sweeter than modern cranberry sauce, but not much. Of course, most people don't put meat in their cranberry sauce these days.
It took almost 200 years for the first cranberry sauce recipe to appear, although other recipes with cranberries appear in a lot of the earlier American cookbooks. America's first published cookbook, American Cookery (1796) by Amelia Simmons, includes a recipe for a cranberry tart, but no cranberry sauce. In The American Frugal Housewife (1833), author Lydia Marie Child includes cranberry pie and cranberry pudding recipes, but again no recipes for cranberry sauce. (Child also discusses using cranberries to remove warts, which I don't recommend fort Thanksgiving dinner.)
Cranberry sauce recipes don't begin to appear in cookbooks in the middle 1800s. I suspect there is a simple reason the earlier cookbooks don't contain cranberry sauce recipes - it's just so simple to make. Boil berries with sugar and water. That's it! I suppose it would have been like including a recipe for making a peanut butter and sandwich.
*If you know a verifiably earlier reference to cranberry sauce, or an earlier recipe, please let me know. I've seen some references on Wikipedia to a "Pilgrim cookbook" from 1663, but I can't find that actual cookbook anywhere. Wikipedia also misquotes Josselyn's book, claiming he called it "sauce for Pilgrims," which is not the case, so I'm feeling a little skeptical about Wikipedia and cranberry history.