-
Notifications
You must be signed in to change notification settings - Fork 967
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
Mj Include crash on latest Beta #1607
Comments
Hi @nagman thanks for reporting this. Concerning the first point, head components are not handled the same way as body components. |
@kmcb777 In fact, I already tested with
And I still get the same error:
|
Same error here. Something worth noting is that when I use |
VSCode plugin isn't updated to 4.4.X beta yet, so it confirms that it's a bug introduced in 4.4.X |
I made several tests, with the cli and as an import in a node app, and everything worked fine. It turns out that even without the mjml and mj-head tags in the included file, it works. @nagman How do you install mjml exactly ? Your version could still be linked to other version's package, it happens sometimes. @vdsabev Do you use mjml with the cli, or as a package in a node app ? |
@kmcb777 |
@nagman @vdsabev |
@kmcb777 Or maybe mjml does something strange with the path. But how can I check it? |
@nagman to investigate the path problem you can just move your mj-include to a position where it doesn't crash the process, if the included file is not found then in the html output it will replace the mj-include with a comment, saying |
@kmcb777 er... So I made tests and the behavior is VERY strange. I have a header and a footer partials. If I include the header before the content, it crashes.
And I don't have any Also, if I change the |
@nagman Can you create a small repo to reproduce the issue you're encountering ? It would help a lot to check what's going on, if you can provide all of those cases, it would help use to create a proper test suite on the parser to prevent those weird issues |
@nagman when you say 'it works', it doesn't crash, but is your mj-include correctly included ? During my tests, what i saw is that when a mj-include fails, the position in the mjml tree is not correctly reset by the parser, and the next element is incorrectly placed. (This is what i fix in the commit referenced above). I never got any of these errors when the mj-include path is correct, so if you can reproduce with a valid include, please provide the mjml files and folder structure you're using, i couldn't reproduce with the examples provided above |
@nagman any news on that ? |
@iRyusa Here's the test repo: I've noticed that it doesn't crash if the mjml file is at the root of the project. But according to my project complexity, I surely cannot put my mjml templates at the root. |
Ok then I understand the issue, you're not providing the |
I've just updated the repo with two more tests. You will see that the filePath option doesn't change anything. |
Ok, I've managed it. I actually thought that the Example:
So you need to Couldn't it be set by default? |
You're passing a string to mjml2html so it has no idea of what is the current file/context, it will default to current |
@iRyusa You're right. Is there any way not to use |
Nope, it only take a string as an input. But it's not really that hard to do something like that : const transpileMjmlFromFile = (filePath) => mjml2html(readFileSync(join(__dirname, filePath), 'utf8'), {filePath}) |
Describe the bug
When I put a
mj-include
inmj-head
, node throws this:To Reproduce
email.mjml
partials/style.mjml
Expected behavior
It should compile nicely.
MJML environment (please complete the following information):
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 firstmj-body
tag:email.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.
The text was updated successfully, but these errors were encountered: