Yovach / next-public-ts

A webpack plugin to compile TypeScript and JavaScript files into the public folder of a Next.js project
6 stars 0 forks source link

Support generating file that is not a module #50

Closed mrdomino closed 9 months ago

mrdomino commented 10 months ago

https://github.com/vercel/next.js/issues/33863#issuecomment-1783841956

Hmm, somehow my sw.js file (generated from something like the ts you showed) is ending up with an export statement in it at the end that is tripping up my browser. Investigating... any ideas? EDIT: Ah, type: 'module' in serviceWorker.register is probably it.

I'll fix the issue because sometimes, you don't need that and it includes unnecessary code

Yovach commented 10 months ago

I don't think that's possible to avoid the type module as we need to use export type in sw.ts. If I configure swc to use non-module files, it crashes with

   × 'import', and 'export' cannot be used outside of module code
   ╭─[1:1]
 1 │ /// <reference lib="WebWorker" />
 2 │ export type {};
   · ──────
 3 │ declare let self: ServiceWorkerGlobalScope;
 4 │ 
 5 │ self.addEventListener("install", async () => {
mrdomino commented 10 months ago

What is the export type doing?

Yovach commented 10 months ago

The export type {}; line is just a placeholder, otherwise Typescript cries

Yovach commented 9 months ago

Can I close the issue as the problem seems to have been resolved?

mrdomino commented 9 months ago

Sure. I would say not planned rather than resolved though.