Skip to content

Commit 70dcea9

Browse files
committed
Add error handling to workbox import.
1 parent f35a687 commit 70dcea9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/client/build/register.ts

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

3838
async function register() {
3939
if ('serviceWorker' in navigator) {
40-
const { Workbox } = await import('workbox-window')
40+
const { Workbox } = await import('workbox-window').catch(() => ({Workbox: null}));
41+
if (!Workbox) {
42+
// Workbox could not be imported.
43+
return;
44+
}
45+
4146
// __SW__, __SCOPE__ and __TYPE__ will be replaced by virtual module
4247
wb = new Workbox('__SW__', { scope: '__SCOPE__', type: '__TYPE__' })
4348
sendSkipWaitingMessage = async () => {

0 commit comments

Comments
 (0)