2016-12-29 10 views
1

serviceworker gemを使用してRailsアプリケーションにサービスワーカーを追加しようとしています。ExecJS :: RuntimeError:SyntaxError:予期しないトークン:name(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)

私のエラーは、サービスエンジニアのgemファイルで提供されたトークン名(catch)が原因です。

は、ここで私はちょうど問題を解決する方法がわからないんだけど、私はエラーが.catchであることを理解エラーが発生している私のコード...

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 
      }) 
     }) 
    ); 

です。

ご協力いただきありがとうございます!

+0

、(。)であるべきです。私はそれを見落としました。なぜなら、構文上の問題では何も起こっていないからです。ありがとうございました! –

答えて

1

2ドットの構文エラー。改行によって、気付きにくいことがあります。

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 
     }) 
    }) 
); 
関連する問題