2016-12-29 2 views
1

Я пытаюсь добавить сервисного работника в мое приложение Rails с драгоценным камнем serviceworker.ExecJS :: RuntimeError: SyntaxError: Неожиданный токен: имя (catch) (строка: 41, col: 8, pos: 1392)

Я следую этому руководству https://rossta.net/blog/offline-page-for-your-rails-application.html и начал получать ошибку, указанную в названии.

Я рассмотрел другие вопросы, подобные, но большинство из них связано с ошибками синтаксиса. Поскольку этот пост Rails 5 Heroku deploy error: ExecJS::ProgramError: SyntaxError: Unexpected token: name (autoRegisterNamespace)

Моя ошибка связана с именем маркера (catch), которое было предоставлено через файл gem serviceworker.

Вот мой код, где происходит ошибка ...

function onFetch(event) { 
    // Fetch from network, fallback to cached content, then offline.html for same-origin GET requests 
    var request = event.request; 

    if (!request.url.match(/^https?:\/\/example.com/)) { return; } 
    if (request.method !== 'GET') { return; } 

    event.respondWith(
    fetch(request).          // first, the network 
     .catch(function fallback() { 
      caches.match(request).then(function(response) { // then, the cache 
      response || caches.match("/offline.html.erb");  // then, /offline cache 
      }) 
     }) 
    ); 

Я понимаю, что ошибка в .catch, я просто не знаю, как решить эту проблему.

Любая помощь очень ценится, спасибо!

+0

Это было его, (.) В конце выборки был причиной ошибки. Я упустил это из виду, потому что ничего не было сказано о синтаксической проблеме. Спасибо! –

ответ

1

Синтаксическая ошибка с двумя точками. Иногда прерывание строки затрудняет уведомление.

event.respondWith(
fetch(request). // Dot here and then... 
    .catch(function fallback() { // ... the one at beginning of line as well causes the issue... 
     caches.match(request).then(function(response) { // then, the cache 
     response || caches.match("/offline.html.erb");  // then, /offline cache 
     }) 
    }) 
); 

Должно быть

event.respondWith(
fetch(request)          // remove dot 
    .catch(function fallback() { 
     caches.match(request).then(function(response) { // then, the cache 
     response || caches.match("/offline.html.erb");  // then, /offline cache 
     }) 
    }) 
); 
Смежные вопросы