shadowwalker / next-pwa

Zero config PWA plugin for Next.js, with workbox 🧰
MIT License
3.71k stars 312 forks source link

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

Open alirezas opened 8 months ago

alirezas commented 8 months ago

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

mostafa-rio commented 8 months ago

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

mugavri commented 8 months ago

lifecycle events

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

busybox11 commented 7 months ago

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

raphaeldevs commented 4 months ago

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

LyghtCode commented 4 months ago

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

raphaeldevs commented 4 months ago

Can you show the error? @LyghtCode