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

Uncaught ReferenceError: window is not defined #1194

Closed
octave opened this issue Nov 19, 2024 · 2 comments
Closed

Uncaught ReferenceError: window is not defined #1194

octave opened this issue Nov 19, 2024 · 2 comments

Comments

@octave
Copy link

octave commented Nov 19, 2024

When using @segment/[email protected] in a @shopify/[email protected] application, deploying fails after building with this error:

 Uncaught ReferenceError: window is not defined  
   at worker.mjs:5087:5433                                                  
   at worker.mjs:5087:17531   

After investigating the worker.mjs the issue seems to be coming from analytics.js-video-plugins that is being added at the end of the worker.mjs file, even though I only import AnalyticsBrowser:

import {AnalyticsBrowser} from '@segment/analytics-next';

It works fine in development but it fails to deploy. Is it possible to not have analytics.js-video-plugins added to the build?

@silesky
Copy link
Contributor

silesky commented Nov 19, 2024

@octave There is no current way to exclude analytics.js-video-plugins.

The window object is assumed to be available. Disabling this plugin probably wouldn't be sufficient, as fixing this error would probably just mean another error appears in another plugin.

If you want to test simply disabling it, you can use this (unstable, use at your own risk API):

  analytics.load({ writeKey: 'foo' }, {
    updateCDNSettings: (unstableSettings) => {
      unstableSettings.legacyVideoPluginsEnabled = false
      return settings
  } })

@octave
Copy link
Author

octave commented Nov 19, 2024

@silesky got it, I ended up reverting to using the script tag directly, this way it doesn't get bundled in the app and so the deployment works. Thanks!

@silesky silesky closed this as completed Nov 19, 2024
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

2 participants