QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.83k stars 1.31k forks source link

Qwik won't build If I try using Broadcast Channel #5893

Open Nedimko123 opened 8 months ago

Nedimko123 commented 8 months ago

it gets stuck at built client modules

Nedimko123 commented 8 months ago

And is it possible to create something similiar with your own service-worker.ts:


/*
 * WHAT IS THIS FILE?
 *
 * The service-worker.ts file is used to have state of the art prefetching.
 * https://qwik.builder.io/qwikcity/prefetching/overview/
 *
 * Qwik uses a service worker to speed up your site and reduce latency, ie, not used in the traditional way of offline.
 * You can also use this file to add more functionality that runs in the service worker.
 */
import { setupServiceWorker } from '@builder.io/qwik-city/service-worker'

setupServiceWorker()

addEventListener('install', () => self.skipWaiting())

addEventListener('activate', () => self.clients.claim())

declare const self: ServiceWorkerGlobalScope
wmertens commented 8 months ago

This is most likely not related to Qwik but to Vite. Try with different Vite versions, v4/v5 and run the build with the environment DEBUG=*

Nedimko123 commented 8 months ago

Tested with "vite": "5.1.4", and "vite": "4.4.6", still the same issue

wmertens commented 8 months ago

Did the DEBUG=* help with showing what is going on? Does it work in dev mode?

Nedimko123 commented 8 months ago

Well that's the thing it works completely fine in dev mode, debug doesn't say anything, it just gets stuck at built client modules...

Nedimko123 commented 8 months ago

Here is the error both if I put as a normal or dev dependancy:

error during build:
Error: No usable method found in ["native","idb","localstorage"]
    at yk (file:///home/nedim/Documents/Motism/REI/frontend_mono/apps/reiprint/.vercel/output/functions/_qwik-city.func/assets/@qwik-city-plan-00616d92.js:100:56987)
    at new _0 (file:///home/nedim/Documents/Motism/REI/frontend_mono/apps/reiprint/.vercel/output/functions/_qwik-city.func/assets/@qwik-city-plan-00616d92.js:100:57195)
    at file:///home/nedim/Documents/Motism/REI/frontend_mono/apps/reiprint/.vercel/output/functions/_qwik-city.func/assets/@qwik-city-plan-00616d92.js:100:59330
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
    at async createSingleThreadWorker (file:///home/nedim/Documents/Motism/REI/frontend_mono/node_modules/.pnpm/@builder.io+qwik-city@1.1.5/node_modules/@builder.io/qwik-city/static/node.mjs:124:14)
    at async createNodeMainProcess (file:///home/nedim/Documents/Motism/REI/frontend_mono/node_modules/.pnpm/@builder.io+qwik-city@1.1.5/node_modules/@builder.io/qwik-city/static/node.mjs:372:30)
    at async mainThread (file:///home/nedim/Documents/Motism/REI/frontend_mono/node_modules/.pnpm/@builder.io+qwik-city@1.1.5/node_modules/@builder.io/qwik-city/static/node.mjs:879:16)
    at async Module.generate (file:///home/nedim/Documents/Motism/REI/frontend_mono/node_modules/.pnpm/@builder.io+qwik-city@1.1.5/node_modules/@builder.io/qwik-city/static/node.mjs:1071:20)
    at async Module.generate (/home/nedim/Documents/Motism/REI/frontend_mono/node_modules/.pnpm/@builder.io+qwik-city@1.1.5/node_modules/@builder.io/qwik-city/static/index.cjs:28:18)

 ELIFECYCLE  Command failed with exit code 1.
wmertens commented 8 months ago

Seems like something wants to store stuff using client side storage options. What is that?

Nedimko123 commented 8 months ago

I mean I literally installed https://www.npmjs.com/package/broadcast-channel and did this to show you that error:

import { BroadcastChannel } from 'broadcast-channel';
const channel = new BroadcastChannel('foobar');
wmertens commented 8 months ago

You're running the broadcast-channel code in the server. You need to encapsulate it so it only runs on the client.

gioboa commented 5 months ago

@Nedimko123 Did you solve your issue with @wmertens solution?

github-actions[bot] commented 5 months ago

Hello @Nedimko123. Please provide the missing information requested above. Issues marked with STATUS-2: missing info will be automatically closed if they have no activity within 14 days. Thanks 🙏

Nedimko123 commented 5 months ago

@gioboa No

gioboa commented 5 months ago

Do you have a public repository to clone and check the problem?