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

Vite project not starting in development mode without broadcast-channel installed #63

Open
philip-weber opened this issue Nov 14, 2021 · 4 comments

Comments

@philip-weber
Copy link

After updating to release 1.5.0 I needed to install broadcast-channel manually to get my project running in development mode. The production bundle, on the other hand, can be created without the dependency without any problems and works perfectly. I'm not using the broadcastQueryClient in my project. I use vite@2.6.14. Of course I can install broadcast-channel but I thought it would not be needed as of release 1.5.0. Or did I understand the release notes wrong? Do I have to make certain settings in vite for it to work? I have already excluded @sveltestack/svelte-query in the vite.config.js.

[vite] Internal server error: Failed to resolve import "broadcast-channel" from "node_modules/@sveltestack/svelte-query/svelte/queryCore/broadcastQueryClient-experimental/index.js". Does the file exist?
Plugin: vite:import-analysis
File: /Users/XXXXX/node_modules/@sveltestack/svelte-query/svelte/queryCore/broadcastQueryClient-experimental/index.js
1  |  import '../core';
2  |  export async function broadcastQueryClient({ queryClient, broadcastChannel = 'svelte-query', }) {
3  |      const { BroadcastChannel } = await import('broadcast-channel');
   |                                                ^
4  |      let transaction = false;
5  |      const tx = (cb) => {
@SomaticIT
Copy link
Collaborator

SomaticIT commented Dec 8, 2021

Hello,

Indeed, we tried to make broadcast-channel an optional dependency since it's only used in broadcastQueryClient to reduce the package size.

It created a side effect with vite which tries to load it even if you do not use broadcastQueryClient. Maybe we could open an issue on the vite side to improve this behavior.

As a workaround, you can exclude broadcast-channel from the dependency pre-bundling process.

Edit 1:
I created a minimal reproduction projects, it seems that added svelte-query or broadcast-channel is not enough to workaround this issue.

Edit 2:
I filled an issue on the vite project (vitejs/vite#6007) to see if it's possible to better handle optional dynamically imported dependencies.

@winston0410
Copy link

@SomaticIT @SomaticIT Are you able to use svelte-query with SvelteKit right now? I have tried to build the app with svelte-query installed, but still it has failed due to the broadcast-channel package

@SomaticIT
Copy link
Collaborator

I use it on a SvelteKit project in SPA mode.
I have to install broadcast-channel to allow vite to analyze imports.

@swyxio
Copy link

swyxio commented Jun 18, 2022

@SomaticIT i actually installed broadcast-channel but am still getting this error. no idea how to resolve.

image

update: solved by deleting .svelte-kit and installing svelte query again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants