Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alirezas opened this issue Oct 24, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@alirezas
Copy link

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 alirezas added the bug Something isn't working label Oct 24, 2023
@mostafa-rio
Copy link

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

@mugavri
Copy link

mugavri commented Nov 6, 2023

@busybox11
Copy link

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
Copy link

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
Copy link

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

@raphaeldevs
Copy link

Can you show the error? @LyghtCode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants