next-pwa
next-pwa copied to clipboard
Property 'workbox' does not exist on type 'Window & typeof globalThis'.ts(2339)
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
Could you please describe the context of the code that you're getting this error from?
lifecycle events
https://github.com/shadowwalker/next-pwa/blob/master/examples/lifecycle/pages/index.js
Also getting this TypeScript error. Just set it up on my NextJS project with next-pwa, window.workbox
does not have any type definition
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:
Im still getting the same error in the ts-config and i did what you had suggested @raphaeldevs
Can you show the error? @LyghtCode