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

Modern TypeScript Module Workaround #5

Open
Offroaders123 opened this issue Oct 15, 2022 · 1 comment
Open

Modern TypeScript Module Workaround #5

Offroaders123 opened this issue Oct 15, 2022 · 1 comment

Comments

@Offroaders123
Copy link

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!

@alexbruno
Copy link

microsoft/TypeScript#11781 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants