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

Still issues with broadcast-channel dependency and svelte-kit #45

Closed
frederikhors opened this issue May 24, 2021 · 12 comments
Closed

Still issues with broadcast-channel dependency and svelte-kit #45

frederikhors opened this issue May 24, 2021 · 12 comments

Comments

@frederikhors
Copy link
Collaborator

@amen-souissi @benmccann I tried 1.4.1 now.

We still have a problem with broadcast-channel if I remove these lines from svelte.config.js:

vite: {
  optimizeDeps: {
    include: ['broadcast-channel']
  },
}

This is the log:

1:22:06 AM [vite] Error when evaluating SSR module /node_modules/broadcast-channel/dist/es/method-chooser.js:
ReferenceError: require is not defined
    at eval (/node_modules/broadcast-channel/dist/es/method-chooser.js:26:20)
    at instantiateModule (C:\kit\node_modules\vite\dist\node\chunks\dep-e9a16784.js:68197:166)

Do you have any idea?

Maybe this is related to "type": "module" in package.json which is the default in a new SvelteKit project, right?

@benmccann
Copy link
Contributor

@frederikhors can you provide a small sample project to reproduce? I can try taking a look to see what the issue is then

@frederikhors
Copy link
Collaborator Author

  • npm init svelte@next my-app
  • cd my-app
  • npm install
  • npm install --save @sveltestack/svelte-query
  • npm run dev

I'm using Windows 10.

@benmccann
Copy link
Contributor

I have no issue on Linux. Maybe you're hitting the Vite Windows bug vitejs/vite#2393

@frederikhors
Copy link
Collaborator Author

Oh. Although the error is slightly different.

We wait for that bug to be closed so check back here, please.

@marcomonsanto
Copy link

marcomonsanto commented Jun 2, 2021

Hi, I have the same issue. I'm using macOS.

500
require is not defined

ReferenceError: require is not defined
at /node_modules/broadcast-channel/dist/es/method-chooser.js:19:20
at instantiateModule (/Users/marcomonsanto/Documents/pessoal/crypto-wallet-svelte/node_modules/vite/dist/node/chunks/dep-e9a16784.js:68197:166)

My dep:
"@sveltestack/svelte-query": "^1.4.1",

@benmccann
Copy link
Contributor

@marcomonsanto can you provide a repo and instructions to reproduce? I just tried the steps above again that @frederikhors provided and still don't see any error

@darekaze
Copy link

darekaze commented Jun 8, 2021

Hi, I don't think this is a window-only bug, cuz I also got this error using Ubuntu Linux. Even I tested a basic repo running in codesandbox, I still got the same error.

Here is a reproduce repo made in Code Sandbox, hope this help: https://codesandbox.io/s/svelte-query-bug-141-f0ksh

Updates: For workaround, make sure broadcast-channel is presented in vite.optimizeDeps.include.

vite: {
  optimizeDeps: {
    include: ['broadcast-channel']
  },
}

@benmccann
Copy link
Contributor

Thanks for providing the repo. That's a bug in broadcast-channel: https://github.com/pubkey/broadcast-channel/issues/636

@dimfeld
Copy link

dimfeld commented Jul 16, 2021

This isn't a real solution that can be merged into broadcast-channel, but as the relevant issue on that repo was closed, I made a fork that removes NodeJS support and the related call to require.

https://github.com/dimfeld/broadcast-channel

I'm not using the broadcast functionality in svelte-query, so can't guarantee that it still works, but the changes were minor. Hopefully it helps someone until a proper solution arrives:

You can use pnpm overrides, yarn resolutions, or a similar mechanism to force svelte-query to use it.

@derolf
Copy link

derolf commented Oct 6, 2021

I am getting

XXX/node_modules/.pnpm/broadcast-channel@4.2.0/node_modules/broadcast-channel/dist/esnode/index.js:1
export { BroadcastChannel, clearNodeFolder, enforceOptions } from './broadcast-channel';

using adapter-static

@benmccann
Copy link
Contributor

There needs to be a new release of the library. There was an improvement committed, but not released yet: #51 (comment)

@SomaticIT
Copy link
Collaborator

Hello,

A new version (v1.5.0) of this library has been published today.
This version makes broadcast-channel an optional dependency.
This should fix all problems with svelte-kit.

If you need to use the experimental broadcastQueryClient, you now need to install it manually (see: broadcastQueryClient).

If you still encounter issues with v1.5.0. Please open a new issue.

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

Successfully merging a pull request may close this issue.

7 participants