Workbox: Cannot find name "ExtendableEvent" and "FetchEvent" running tsc

Created on 6 Aug 2019  路  2Comments  路  Source: GoogleChrome/workbox

Library Affected:
workbox-strategies, workbox-core

Browser & Platform:
build

Issue or Feature Request Description:
We weren't setting skipLibCheck: true in our tsconfig files, and when doing so with the latest alpha2 we were seeing the following typescript errors:

node_modules/workbox-strategies/CacheFirst.d.ts(60,47): error TS2304: Cannot find name 'ExtendableEvent'.
node_modules/workbox-strategies/node_modules/workbox-core/types.d.ts(8,13): error TS2304: Cannot find name 'ExtendableEvent'.
node_modules/workbox-strategies/node_modules/workbox-core/types.d.ts(59,17): error TS2304: Cannot find name 'FetchEvent'.
node_modules/workbox-strategies/node_modules/workbox-core/types.d.ts(72,17): error TS2304: Cannot find name 'ExtendableEvent'.
node_modules/workbox-strategies/node_modules/workbox-core/types.d.ts(81,17): error TS2304: Cannot find name 'ExtendableEvent'.
node_modules/workbox-strategies/node_modules/workbox-core/types.d.ts(89,17): error TS2304: Cannot find name 'ExtendableEvent'.
node_modules/workbox-strategies/StaleWhileRevalidate.d.ts(68,17): error TS2304: Cannot find name 'ExtendableEvent'.

Most helpful comment

Can you share the compiler options in your tsconfig. They should include "webworker"

{
  "compilerOptions": {
    "lib": ["esnext", "webworker"]
  }
}

You will have to create multiple tsconfig, one for your Service Worker and another for the rest of your project.

You can check out this Stackoverflow question https://stackoverflow.com/questions/56356655/structuring-a-typescript-project-with-workers/56374158#56374158 for more info.
I've followed the same in my repo

All 2 comments

Can you share the compiler options in your tsconfig. They should include "webworker"

{
  "compilerOptions": {
    "lib": ["esnext", "webworker"]
  }
}

You will have to create multiple tsconfig, one for your Service Worker and another for the rest of your project.

You can check out this Stackoverflow question https://stackoverflow.com/questions/56356655/structuring-a-typescript-project-with-workers/56374158#56374158 for more info.
I've followed the same in my repo

Ouch, that definitely works but I guess was super non-obvious about that. Thanks for the info and resolution, I think I'll have to update the structure of my project a bit but can workaround it.

Was this page helpful?
0 / 5 - 0 ratings