Magento – Order mail confirmation generates DOMXPath::query() error

checkouterrormagento2order-email

on order place the email contains the following error and does not display properly

CSS Inline Error: Warning: DOMXPath::query(): Invalid expression in .../vendor/pelago/emogrifier/Classes/Emogrifier.php on line 269 

How do I fix this?

Best Answer

This may be a bug of Emogrifier module.

Put this in the require-dev part of composer.json:

"pelago/emogrifier": "1.0.0 as 0.1.1"

Or prefer the development version:

"pelago/emogrifier": "dev-master as 0.1.1"

There is a notice: seem that this issue also occurs when processing static content deploy.

UPDATE:

We should take a look:

vendor/magento/theme-frontend-blank/web/css/email.less

@import 'source/lib/_lib.less'; // Global lib
@import 'source/lib/variables/_email.less'; // Global email variables
@import 'source/_theme.less'; // Global variables override
@import 'source/_variables.less'; // Local theme variables
@import 'source/_email-variables.less'; // Theme variables for emails

Magento email will import some less files. So, if we added some unsupported selectors to these files, that may cause this issue.

vendor/magento/theme-frontend-blank/web/css/source/_email-base.less

Unsupported selectors (examples in parenthesis):
      * first-child (div:first-child)
      * last-child (div:last-child)
      * nth-child (div:nth-child(3n+1))
      * universal (*)
      * pseudo (a:hover, a:active, a:focus, span:before, span:after, etc)

For example, in our custom theme, we add some unsupported selectors:

app/design/frontend/VendorTheme/default/web/css/source/_theme.less

...
#customer-service-menu li.item:nth-child(2) {position: absolute;}
...

This issue will occurs again.

SOLUTION:

We should create a new folder which contains the stand less files for our email styles. And, these files are only for email.

app/design/frontend/VendorTheme/default/web/css/email.less

@import 'source/lib/email/stand/_lib.less'; // Global lib
@import 'source/lib/email/stand/variables/_email.less'; // Global email variables
Related Topic