Can't add documents to lunr index after assignment (TypeError: idx.add is not a function)
The tutorial you linked to is for an older version of Lunr. The latest version requires you to add all documents to the index within the function you pass to the lunr
function. In other words, your second example is correct for the latest version of Lunr.
There is a guide on upgrading to the latest version which should hopefully cover the difference between the old versions from that (and other) tutorials and the latest version.