Skip to content

Make hooks compatible with non-Vite builds #428

Closed
@joetannenbaum

Description

@joetannenbaum

@tnylea Thanks for your amazing work.

When trying to use Laravel Echo's React Hook in Next.js, I initialized the Echo configuration as follows:

configureEcho({
  broadcaster: "reverb",
  key: 'my-app-key',
  wsHost: 'localhost',
  wsPort: 8010,
  wssPort: 8010,
  forceTLS: false,
  enabledTransports: ['ws', 'wss'],
});

However, the error message is as follows:

Uncaught Error: Cannot read properties of undefined (reading 'VITE_REVERB_KEY')

This issue occurs because of the dependency on Vite’s environment variable reading method in https://github.com/laravel/echo/blob/2.x/packages/react/src/config/index.ts#L37-L43, which is not applicable to Next.js or other non-Vite environments.

I would like to have a way to provide a custom configuration instance, or allow Echo initialization without depending on a specific build tool (like Vite), so it can work in any React environment, especially in frameworks like Next.js.

I hope to see a method for initialization that does not rely on a specific framework, or a way to resolve this issue via custom instances.

Thanks.

Originally posted by @overtrue in #422 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions