Skip to content

mjml2html render in web worker throws Uncaught ReferenceError: window is not defined #2853

Open
@jlarmstrongiv

Description

@jlarmstrongiv

Describe the bug

In a web worker:

mjml-browser.js?v=275a58ae:25 Uncaught ReferenceError: window is not defined
    at ../../../node_modules/mjml-browser/lib/index.js (mjml-browser.js?v=275a58ae:25:7)
    at __require2 (chunk-IRSSH5FH.js?v=275a58ae:23:50)
    at mjml-browser.js?v=275a58ae:24126:16

To Reproduce
Steps to reproduce the behavior:

  1. In vite, create a web worker
  2. Try importing import mjml2html from "mjml-browser";
  3. See error

Expected behavior
I expect mjml-browser to work in web workers, without throwing any errors. It’s a cpu heavy process that would be perfect for web workers

MJML environment (please complete the following information):

  • OS: MacOS
  • MJML Version: 4.15.3
  • MJML tool used: mjml-browser

Email sending environment(for rendering issues):
N/A

Affected email clients (for rendering issues):
N/A

Screenshots
N/A

Additional context
window is not a global variable in web workers https://stackoverflow.com/a/11237259

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