Skip to content

Bypass import.meta.env type checking on React Native (or possibly other non-Vite projects) #453

@vinzlee97

Description

@vinzlee97

Echo Version

2.2.0

Laravel Version

12.4.0

PHP Version

8.2.29

NPM Version

24.6.0

Database Driver & Version

No response

Description

Hello team, and thanks for the great package!

This issue might be related to this, but instead of React, it is on React Native project. Since the server uses Reverb, I choose to use Laravel Echo on the client. Based on this PR, I see this additional import.meta.env type check, but on Metro it immediately refuses to acknowledge import.meta as it is unsupported.

Image

So my temporary solution is to comment out the defaults which uses import.meta.env altogether, then rebuilt the dist folder. This works, but I have to do this patch everytime new release comes in.

    const defaults: ConfigDefaults<BroadcastDriver> = {
        reverb: {
            broadcaster: "reverb",
-            key: import.meta.env.VITE_REVERB_APP_KEY,
-            wsHost: import.meta.env.VITE_REVERB_HOST,
-            wsPort: import.meta.env.VITE_REVERB_PORT,
-            wssPort: import.meta.env.VITE_REVERB_PORT,
-            forceTLS:
-                 (import.meta.env.VITE_REVERB_SCHEME ?? "https") === "https",
+            // key: import.meta.env.VITE_REVERB_APP_KEY,
+            // wsHost: import.meta.env.VITE_REVERB_HOST,
+            // wsPort: import.meta.env.VITE_REVERB_PORT,
+            // wssPort: import.meta.env.VITE_REVERB_PORT,
+            // forceTLS:
+            //     (import.meta.env.VITE_REVERB_SCHEME ?? "https") === "https",
+            forceTLS: true,
            enabledTransports: ["ws", "wss"],
        },
        ...

I'm thinking the config can use some kind of flag to indicate whether the defaults can grab from import.meta.env (which Vite projects most certainly uses), so that it doesn't have to rely on import.meta.env, hence won't do the type checking (e.g. useImportMetaEnvForDefaults which defaults to true if not provided), but I'm curious about your thoughts on this. Thanks in advance!

Steps To Reproduce

.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions