0

Problem: Lunr.js indexes and loads static site content JSON file, but does not work when deployed. It does work in development with LiveReload but does not when deployed.

I've set the CORS options on AWS to allow all requests and it had no effect.


Framework: Middleman 4.0

Gem: Middleman-Search

JS: Lunr.js 0.7.0 (although, the problem was duplicated with 0.7.2)

Host: Amazon S3 static site hosting


When the page loads, I immediately get this error in the console because the AJAX request to download and cache the search index is a self executing function expression.

This is my stack trace:

Uncaught TypeError: Cannot read property 'version' of undefined
    at Function.t.Index.load (all.js:95)
    at Object.success (all.js:95)
    at u (all.js:3)
    at Object.fireWith [as resolveWith] (all.js:3)
    at i (all.js:4)
    at XMLHttpRequest.<anonymous> (all.js:4)

Below is the rabbit hole. Any idea how I can fix this?

all.js:95 Uncaught TypeError: Cannot read property 'version' of undefined

at Function.t.Index.load (all.js:95)

t.Index.prototype.off = function(t, e) {
  return this.eventEmitter.removeListener(t, e)
}

at Object.success (all.js:95)

Takes me to the end of Lunrjs self-executing function expression.

at u (all.js:3)

dt.Callbacks = function(t) {
  t = "string" == typeof t ? s(t) : dt.extend({}, t);
  var e, n, i, o, r = [], a = [], l = -1, u = function() {
      for (o = t.once,
      i = e = !0; a.length; l = -1)
          for (n = a.shift(); ++l < r.length; )
              r[l].apply(n[0], n[1]) === !1 && t.stopOnFalse && (l = r.length,
              n = !1);
      t.memory || (n = !1),
   `   e = !1,
      o && (r = n ? [] : "")

at Object.fireWith [as resolveWith] (all.js:3)

     fireWith: function(t, n) {
                     return o || (n = n || [],
                     n = [t, n.slice ? n.slice() : n],
                     a.push(n),
                     e || u()),
                   this
                 },

at i (all.js:4)

u ? m.resolveWith(g, [f, T, S]) : m.rejectWith(g, [S, T, p]),

at XMLHttpRequest. (all.js:4)

"abort" === t ? a.abort() : "error" === t ? "number" != typeof a.status ? r(0, "error") : r(a.status, a.statusText) : r(We[a.status] || a.status, a.statusText, "text" !== (a.responseType || "text") || "string" != typeof a.responseText ? {

I'm at a point where I don't understand what I don't understand and where to probe to figure out if I caused this issue or not. It could be a Lunrjs, Amazon S3, CORS, or Middleman problem.

splatoperator
  • 227
  • 1
  • 2
  • 10
  • Maybe the problem arises when your JavaScripts are minified. That's a common thing to do on build but not on development. – rb- Feb 05 '17 at 20:55
  • The error message looks like lunr is trying (and failing) to find the `version` field in what it assumes to a serialised index. What are you passing to `lunr.Index.load`? – Oliver Nightingale May 20 '17 at 13:29

0 Answers0