-
Notifications
You must be signed in to change notification settings - Fork 7
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
Modern TypeScript Module Workaround #5
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: