PHP League Commonmark $environment error in Laravel cached view

1.6k views Asked by At

After upgrading a Laravel project to PHP8 I'm getting this error pretty often:

Passing an $environment into the "League\CommonMark\CommonMarkConverter" constructor is deprecated in 1.6 and will not be supported in 2.0; use MarkdownConverter instead

The stack trace shows it's triggered by this line in a cached view file:

<?php echo e(Illuminate\Mail\Markdown::parse($slot)); ?>

I have deleted all cached views multiple times (I thought that there were maybe some old cached ones in there) but that didn't solve it.

Not sure if this should be an error that's reported as it might be the case that this is fixed in the Laravel framework, but before upgrading to PHP8 I never had this error so I think it's related to that.

4

There are 4 answers

1
Watercayman On

Banged my head on this one quite a bit too. I kept making changes to the markdown files, but they never showed up - almost like Laravel was pointing to the wrong place. And it was...

I was working on an upgraded Laravel application (I.E. I started with 5.x and have upgraded over time), and thus there are two potential issues.

First, in ip/config/mail.php: you may have to actually create the markdown path. If you published the mailables prior to markdown, the entire markdown mail settings are missing. You can pull them from the git repo, or from here for convenience:

'markdown' => [
    'theme' => 'default',
    'paths' => [
        resource_path('views/vendor/mail'),
    ],
],

Second potential (though less likely in your case) issue if you published these mail files earlier, the Laravel layouts file in the HTML directory has the or operator, which will choke. Change these three operators to ??.

Maybe this will help you, depending on where you started :)

0
Colin O'Dell On

The error you're receiving was supposed to be a silenced deprecation error added in version 1.6.0 of league/commonmark. Unfortunately there was a bug which caused it to be a "user notice" instead of a deprecation notice. Upgrading league/commonmark to 1.6.2 where this was fixed might solve the issue.

If you still receive the error after upgrading (and ensuring that PHP's opcache has been cleared), it's highly likely that Laravel or something else in your code is catching and reporting this silenced error - that's a good thing, as we want people to know this functionality is deprecated and will be removed, but it shouldn't be spamming your logs, so double-check any settings in Laravel or PHP related to error logging, error levels, and logging.

Source: I'm the maintainer of league/commonmark.

0
Goper Leo Zosa On

I also encounter this error. I fix it by downgrading the league/commonmark, see deprecation noticed

composer require league/commonmark 1.6.7
php artisan view:cache

After publishing mailable templates php artisan vendor:publish --tag=laravel-mail

0
eskimo On

Eventually it turned out that I set my PHP version to 8 on Laravel Forge, but not on Laravel Envoyer that I use for deployments... Hope this helps someone who has the same setup!