Skip to content

Mj Include crash on latest Beta #1607

@nagman

Description

@nagman

Describe the bug
When I put a mj-include in mj-head, node throws this:

TypeError: setBackgroundColor is not a function
    at MjBody.render (/api/node_modules/mjml-body/lib/index.js:67:7)
    at /api/node_modules/mjml-core/lib/createComponent.js:336:28
    at Array.map (<anonymous>)
    at MjHead.handlerChildren (/api/node_modules/mjml-core/lib/createComponent.js:317:24)
    at MjHead.handler (/api/node_modules/mjml-head/lib/index.js:43:19)
    at _processing (/api/node_modules/mjml-core/lib/index.js:235:26)
    at Object.mjml2html [as default] (/api/node_modules/mjml-core/lib/index.js:329:25)
    at compileTemplate (/api/src/emails/templates/index.ts:16:30)
    at Object.<anonymous> (/api/src/emails/templates/index.ts:35:5)
    at Module._compile (internal/modules/cjs/loader.js:701:30)

To Reproduce
email.mjml

<mjml>
	<mj-head>
		<mj-include path="./partials/style.mjml" />
	</mj-head>

	<mj-body>
		<mj-section>
			<mj-column>
				<mj-text>Blabla, whatever</mj-text>
			</mj-column>
		</mj-section>
	</mj-body>
</mjml>

partials/style.mjml

<mj-attributes>
	<mj-text font-family="Arial" font-size="14px" line-height="170%" align="center" />
</mj-attributes>

Expected behavior
It should compile nicely.

MJML environment (please complete the following information):

  • OS: Ubuntu 18.04
  • MJML Version: 4.4.0-beta.2
  • MJML tool used: mjml for node

Additional context
When I remove the mj-include, it compiles without error.

Notice that another bug occurs whith mj-include when I put one just after the first mj-body tag:
email.mjml

<mjml>
	<mj-body>
		<mj-include path="./partials/header.mjml" />
		<mj-section>
			<mj-column>
				<mj-text>Blabla, whatever</mj-text>
			</mj-column>
		</mj-section>
	</mj-body>
</mjml>

throws mj-section cannot be used inside mj-raw, only inside: mj-attributes, mj-body, mj-wrapper.

But if I put it before the last mj-body tag AND after a comment, it works.
I mean... it doesn't work at the end (partial is not included) but it doesn't throw anything.

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