Skip to content

Commit 488e1eb

Browse files
committed
Add error handling to workbox import.
1 parent f35a687 commit 488e1eb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/client/build/register.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ export function registerSW(options: RegisterSWOptions = {}) {
3737

3838
async function register() {
3939
if ('serviceWorker' in navigator) {
40-
const { Workbox } = await import('workbox-window')
40+
const WorkboxWindow = await import('workbox-window').catch((e) =>
41+
onRegisterError?.(e)
42+
)
43+
if (!WorkboxWindow) {
44+
return
45+
}
46+
47+
const { Workbox } = WorkboxWindow
4148
// __SW__, __SCOPE__ and __TYPE__ will be replaced by virtual module
4249
wb = new Workbox('__SW__', { scope: '__SCOPE__', type: '__TYPE__' })
4350
sendSkipWaitingMessage = async () => {

0 commit comments

Comments
 (0)