Closed huineng closed 2 years ago
A few things:
@types/workbox-webpack-plugin
if you've updated to workbox-webpack-plugin
v6.5.0
. The official package now includes an index.d.ts
with the TypeScript types, based on the package's source.v6.5.0
, but generally speaking, you shouldn't include dom
in the list of lib
s for your TypeScript configuration when compiling a service worker. The service worker runtime environment exposes a different global interface that what dom
expects.What I'd recommend doing is either create a separate tsconfig.json
for your service worker, or alternatively, add something like this to the top of your service worker's TypeScript:
/// <reference lib="webworker" />
declare const self: ServiceWorkerGlobalScope;
You mention that you're using TypeScript 4.5.5, and there were some changes introduced there to give developers more flexibility in referencing libraries.
as there was no way to solve this ..
my mini-css-extract-plugin needed dom and workbox-webpack-plugin needed webworker. but as i only needed ExtendableEvent which was no more then a a few lines
interface ExtendableEvent extends Event {
waitUntil(f: any): void;
}
i loaded those line into a d.ts file in the same directory as my ts files and i did no longer needed to include webworker and it all compiled
It sounds like you have a workaround, so I'm going to close this issue.
But was using a different TypeScript configuration for each of those compilations not an option?
What I'd recommend doing is either create a separate
tsconfig.json
for your service worker,
@jeffposnick But how does this work when web pack is creating the service worker?
https://developer.chrome.com/docs/workbox/modules/workbox-webpack-plugin/#generatesw-plugin
workbox-webpack-plugin devDep 6.4.1 ❯ 6.5.0 typescript": "^4.5.5 "@types/workbox-webpack-plugin": "^5.1.8",
When upgrading and compiling i hit the following error
but when adding webworker to lib
i hit a bunch of other errors, conflicts
i need to include dom otherwise i get errors there
how can i resolve this ?
thanks