next-pwa icon indicating copy to clipboard operation
next-pwa copied to clipboard

Property 'workbox' does not exist on type 'Window & typeof globalThis'.ts(2339)

Open alirezas opened this issue 1 year ago • 6 comments

Summary

How can I fix this typescript issue? I'm getting this error in the code below:

if ( typeof window !== "undefined" && "serviceWorker" in navigator && window.workbox !== undefined )

Property 'workbox' does not exist on type 'Window & typeof globalThis'.ts(2339)

Versions

  • next-pwa: ^5.6.0
  • next: 13.5.6

alirezas avatar Oct 24 '23 15:10 alirezas

Could you please describe the context of the code that you're getting this error from?

mostafa-rio avatar Oct 26 '23 16:10 mostafa-rio

lifecycle events

https://github.com/shadowwalker/next-pwa/blob/master/examples/lifecycle/pages/index.js

mugavri avatar Nov 06 '23 15:11 mugavri

image

Also getting this TypeScript error. Just set it up on my NextJS project with next-pwa, window.workbox does not have any type definition

busybox11 avatar Nov 29 '23 22:11 busybox11

You can install this package: @types/workbox-window. Then, you should create a folder named @types and a file named workbox.d.ts with the following content:

import { Workbox } from 'workbox-window';

declare global {
  interface Window {
    workbox: Workbox
  }
}

It's works for me: image

raphaeldevs avatar Feb 17 '24 12:02 raphaeldevs

Im still getting the same error in the ts-config and i did what you had suggested @raphaeldevs

LyghtCode avatar Feb 27 '24 06:02 LyghtCode

Can you show the error? @LyghtCode

raphaeldevs avatar Feb 28 '24 13:02 raphaeldevs