You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a similar workaround along these lines for modern TypeScript versions? Relating to this issue here, I am trying to figure out how to write a Service Worker in TypeScript, without a bundler. I'm surprised how difficult it is to set up!
With the addition of the change mentioned in the link above, your example project doesn't appear to work anymore with modern TypeScript versions (after an npm install typescript@latest), because the compiler will now include empty export {} statements in the resulting JavaScript output. This will make the script invalid in a regular Service Worker script which isn't a non type: "module" one. Ideally I could just deal with that by using type: "module" itself, but support for that hasn't carried over to Firefox yet. So, it seems to boil down to using just vanilla JS, or both TypeScript and a bundler! Eeek.
I think a main part of the issue is that one has to add either an import or export to the file to make it a module, in TypeScript's sense. It would be nice to have something like /// <environment type="serviceworker" /> to define if a file is a Service Worker (which could imply that it is also isolated, like that of a module), as recommended over in this thread. But, I guess we can't have nice things 😆
Thanks for finding this original solution! I hope we can figure out a new fix for it. I'll continue to test on my own too.
P.S.
Great work on recent HTTP 203 episodes! It has been sad to miss Surma, but everyone on the show so far has also been amazing. Thanks for all of your hard work and humor!
The text was updated successfully, but these errors were encountered:
Is there a similar workaround along these lines for modern TypeScript versions? Relating to this issue here, I am trying to figure out how to write a Service Worker in TypeScript, without a bundler. I'm surprised how difficult it is to set up!
With the addition of the change mentioned in the link above, your example project doesn't appear to work anymore with modern TypeScript versions (after an
npm install typescript@latest
), because the compiler will now include emptyexport {}
statements in the resulting JavaScript output. This will make the script invalid in a regular Service Worker script which isn't a nontype: "module"
one. Ideally I could just deal with that by usingtype: "module"
itself, but support for that hasn't carried over to Firefox yet. So, it seems to boil down to using just vanilla JS, or both TypeScript and a bundler! Eeek.I think a main part of the issue is that one has to add either an
import
orexport
to the file to make it a module, in TypeScript's sense. It would be nice to have something like/// <environment type="serviceworker" />
to define if a file is a Service Worker (which could imply that it is also isolated, like that of a module), as recommended over in this thread. But, I guess we can't have nice things 😆Thanks for finding this original solution! I hope we can figure out a new fix for it. I'll continue to test on my own too.
P.S.
Great work on recent HTTP 203 episodes! It has been sad to miss Surma, but everyone on the show so far has also been amazing. Thanks for all of your hard work and humor!
The text was updated successfully, but these errors were encountered: