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

Service worker - Uncaught ReferenceError: window is not defined #17882

Closed
lajuffermans opened this issue Mar 5, 2025 · 1 comment
Closed
Assignees
Labels
area/cli area/plugins bug/2-confirmed We have reproduce the problem and confirmed that this is a bug. flavour/quasar-cli-vite kind/bug 🐞 mode/pwa Qv2 🔝 Quasar v2 issues

Comments

@lajuffermans
Copy link

What happened?

When trying to import and use quasar utils or plugin functions in a server worker we get a "Uncaught ReferenceError: window is not defined".

Example, try to do this in custom-service-worker.js:

import { uid } from 'quasar';

console.log(uid())

Image

What did you expect to happen?

  1. When importing uid I didn't expect the Platform plugin to get included too
  2. Maybe __QUASAR_SSR_SERVER__ should be true (https://github.com/quasarframework/quasar/blob/dev/ui/src/plugins/platform/Platform.js#L63) if someone wants to use the Platform plugin in a (service)worker context? (there is no window there)

Reproduction URL

https://stackblitz.com/edit/quasarframework-stackblitz-templates-tahv4cm3?file=src-pwa%2Fcustom-service-worker.js

How to reproduce?

  1. Create a fresh quasa project CLI + VITE
  2. Add PWA mode
  3. Use the InjectManifest mode
  4. Add:
import { uid } from 'quasar';

console.log(uid())
  1. Serve the app in PWA mode

FYI The stackblitz example give you an idea of the code however it looks like service workers do not actually work in such an environment?

Flavour

Quasar CLI with Vite (@quasar/cli | @quasar/app-vite)

Areas

Quasar CLI Commands/Configuration (@quasar/cli | @quasar/app-webpack | @quasar/app-vite), Plugins (quasar), PWA Mode

Platforms/Browsers

Chrome, Firefox

Quasar info output

Operating System - Darwin(23.6.0) - darwin/arm64
NodeJs - 20.9.0

Global packages
  NPM - 10.1.0
  yarn - Not installed
  pnpm - Not installed
  bun - Not installed
  @quasar/cli - undefined
  @quasar/icongenie - Not installed
  cordova - Not installed

Important local packages
  quasar - 2.18.0 -- Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time
  @quasar/app-vite - 2.1.3 -- Quasar Framework App CLI with Vite
  @quasar/extras - 1.16.17 -- Quasar Framework fonts, icons and animations
  eslint-plugin-quasar - Not installed
  vue - 3.5.13 -- The progressive JavaScript framework for building modern web UI.
  vue-router - 4.5.0
  pinia - Not installed
  vite - 6.2.0 -- Native-ESM powered web dev build tool
  vite-plugin-checker - Not installed
  eslint - 9.21.0 -- An AST-based pattern checker for JavaScript.
  esbuild - 0.25.0 -- An extremely fast JavaScript and CSS bundler and minifier.
  typescript - Not installed
  workbox-build - 7.3.0 -- A module that integrates into your build process, helping you generate a manifest of local files that workbox-sw should precache.
  register-service-worker - 1.7.2 -- Script for registering service worker, with hooks
  electron - Not installed
  @electron/packager - Not installed
  electron-builder - Not installed
  @capacitor/core - Not installed
  @capacitor/cli - Not installed
  @capacitor/android - Not installed
  @capacitor/ios - Not installed

Quasar App Extensions
  *None installed*

Relevant log output

Additional context

No response

@yusufkandemir yusufkandemir added bug/2-confirmed We have reproduce the problem and confirmed that this is a bug. and removed bug/1-repro-available A reproduction is available and needs to be confirmed. labels Mar 5, 2025
@rstoenescu
Copy link
Member

Duplicate of #17747

@rstoenescu rstoenescu marked this as a duplicate of #17747 Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli area/plugins bug/2-confirmed We have reproduce the problem and confirmed that this is a bug. flavour/quasar-cli-vite kind/bug 🐞 mode/pwa Qv2 🔝 Quasar v2 issues
Projects
None yet
Development

No branches or pull requests

3 participants