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

BUG: Incompatibility with grape js headless mode #392

Open
3 tasks done
pboneure opened this issue Feb 14, 2025 · 1 comment
Open
3 tasks done

BUG: Incompatibility with grape js headless mode #392

pboneure opened this issue Feb 14, 2025 · 1 comment

Comments

@pboneure
Copy link

pboneure commented Feb 14, 2025

GrapesJS version

  • I confirm to use the latest version of GrapesJS

GrapesJS MJML version

  • I confirm to use the latest version of GrapesJS MJML

What browser are you using?

Not applicable (it's running on a server)

Reproducible demo link

https://codesandbox.io/p/sandbox/m86rgn

Describe the bug

How to reproduce the bug?

  1. Init GrapeJS in headless mode
  2. Try to run command mjml-code-to-html

What is the expected behavior?
The html is created (and does not rely on window since we run it in headless mode).

What is the current behavior?
We have this error :

window is not defined
ReferenceError: window is not defined
    at Object.moduleId [as 480] ...

If is necessary to execute some code in order to reproduce the bug, paste it here below:

  const editor = grapesjs.init({
    telemetry: false,
    headless: true,
    plugins: [usePlugin(grapesJSMJML, { useCustomTheme: false })],
    projectData: {"test": "test"} as ObjectAny,
  });
  console.log(emailEditor.runCommand('mjml-code-to-html').html.toString());

Workaround:

We found a solution by importing global-jsdom/register, that gives a mock of window.

Code of Conduct

  • I agree to follow this project's Code of Conduct
pboneure added a commit to pboneure/mjml that referenced this issue Feb 18, 2025
@pboneure
Copy link
Author

pboneure commented Feb 18, 2025

@artf
Created a fix for this issue in #393
Don't hesitate to tell me if you find a better way.
For this fix to work you need to pass in a custom parser (since the default one uses window)

const emailEditor = grapesjs.init({
                        telemetry: false,
                        headless: true,
                        plugins: [usePlugin(grapesJSMJML, { useCustomTheme: false, mjmlParser: mjml2html })],
                        projectData: JSON.parse(emailJson) as ObjectAny,
                    });
return (emailEditor.runCommand('mjml-code-to-html') as Editor).html;

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

1 participant