question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The bundler generates a "rogue" "export default Fl();" if I import nostr-tools in entry point

See original GitHub issue

Describe 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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
userquincommented, Sep 8, 2022

@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.

0reactions
userquincommented, Sep 9, 2022

@sapphi-red you can also check my summary in kit issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Service Worker Compilation during Development · Issue #5479
The bundler generates a "rogue" "export default Fl();" if I import nostr-tools in entry point vitejs/vite#10035.
Read more >
How can I build a webpack bundle that imports a module from ...
I know that I can use CommonsChunkPlugin to generate a commons.js file containing the WebPack loader and jQuery, but that would require loading ......
Read more >
One entry point per page - Tooling.Report
Instead of being bundled into each page's script, the library should be split out into a bundle shared by both. Splitting common code...
Read more >
The bundler generates a "rogue" "export default Fl();" if I import nostr ...
The bundler generates a "rogue" "export default Fl();" if I import nostr-tools in entry point.
Read more >
Configuration - Preconstruct
Preconstruct accepts configuration at three different configuration points; projects, packages and entrypoints. These configuration points can be ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found