jakearchibald / jakearchibald/typescript-worker-example
Modern TypeScript Module Workaround
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 63
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
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!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the example project and reproduce the problem after running npm install typescript@latest; read the linked TypeScript issue for the module-emission change. Determine whether a workaround can produce a valid classic Service Worker script without a bundler or Firefox module support; done requires the example working with modern TypeScript.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100