The bundler generates a "rogue" "export default Fl();" if I import nostr-tools in entry point
See original GitHub issueDescribe the bug
In src/service-worker.ts I have the sole line:
import { relayPool } from 'nostr-tools'
but the bundle (build/service-worker.js) contains:
export default Fl();
The same happens if I import nostr from 'nostr-tools'
(or probably anything other nostr-tools.
My bundle is free of exports when importing Dexie from 'dexie'
or a bunch of other imports.
I tried to figure out in the vite discord if this “transient” export might be a feature of sorts but I’m more and more convinced it is a bug in the bundler.
This bug was originally reported here.
Reproduction
https://github.com/Giszmo/tmpForBugReport is a blank svelteKit project with the added dependency nostr-tools
and src/service-worker.ts` consisting of only an import from that dependency.
System Info
$ npx envinfo --system --npmPackages '{vite,@vitejs/*}' --binaries --browsers
System:
OS: Linux 5.10 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
Memory: 18.77 GB / 31.33 GB
Container: Yes
Shell: 5.1.4 - /bin/bash
Binaries:
Node: 18.6.0 - ~/.nvm/versions/node/v18.6.0/bin/node
npm: 8.13.2 - ~/.nvm/versions/node/v18.6.0/bin/npm
Browsers:
Chromium: 103.0.5060.53
Firefox: 96.0.3
npmPackages:
vite: ^3.0.0 => 3.0.4
Used Package Manager
npm
Logs
$ npm run build && npm run preview … (no errors)
Chromium dev console:
Uncaught SyntaxError: Unexpected token ‘export’ (at service-worker.js:6207:1)
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:9 (3 by maintainers)
@sapphi-red FYI:
What we do in pwa plugin is this: https://github.com/antfu/vite-plugin-pwa/blob/main/src/modules.ts#L108
On dev with plugin dev enabled, we need the type module when registering the sw and delegates sw build to Vite when using custom sw: https://github.com/antfu/vite-plugin-pwa/blob/main/src/plugins/dev.ts#L108
Otherwise we fallback to workbox-build.
I think the problem is that kit will never build the sw, current/latest and previous versions: talking with Ben, Rich always reject to include workbox-build and so ppl should use
importScripts
.@sapphi-red you can also check my summary in kit issue