You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 20:14:33