Firefox中注册使用ES模块的Service Worker时抛出TypeError导致注册失败求助
Firefox中注册使用ES模块的Service Worker时抛出TypeError导致注册失败求助
大家好,我最近碰到个棘手的问题:在Firefox里注册用ES模块的Service Worker时总是失败,抛出了TypeError,但这套代码在Chrome、Edge和Opera里都能正常跑,实在摸不清头绪,来求助各位!
错误信息
注册失败时的提示是:
SW Registration failed with TypeError: ServiceWorker script at http://localhost/Vanilla/CacheManager.js for scope http://localhost/Vanilla/ threw an exception during script evaluation.
我的Service Worker注册代码
if ("serviceWorker" in navigator) { await navigator.serviceWorker.register('/Vanilla/CacheManager.js', { scope: '/Vanilla/', type: 'module' }) .then(reg => { console.log('SW Registered'); }) .catch(err => { console.log('SW Registration failed with ' + err) }); }
简化后的CacheManager.js代码
问题就出在导入语句这一行:
import config from "/Vanilla/config.js" // The problem console.log("Hello") //const CACHE_NAME = config.cacheName
对应的Config.js代码
export const config = { "cacheName": "VanillaV1.1" }
我完全搞不懂Firefox到底在抱怨什么TypeError,难道是CONST的问题吗?有没有朋友遇到过类似情况,或者能帮我排查下问题根源?
备注:内容来源于stack exchange,提问作者McMurphy
相关产品推荐
相关产品推荐

