Update to twig 1.40.1 (via composer, 1.39.1 work fine) causes errors

Uncaught PHP Exception Twig\\Error\\SyntaxError: "An exception has been thrown during the compilation of a template ("Node "options" does not exist for Node "Drupal\\Core\\Template\\TwigNodeTrans".") in "core/themes/bartik/templates/block--system-menu-block.html.twig"." at /Sites/twigerror/vendor/twig/twig/src/Environment.php line 798

Uncaught PHP Exception Twig\\Error\\SyntaxError: "An exception has been thrown during the compilation of a template ("Node "options" does not exist for Node "Drupal\\Core\\Template\\TwigNodeTrans".") in "core/themes/classy/templates/views/views-mini-pager.html.twig"." at /twigerror/vendor/twig/twig/src/Environment.php line 798, referer: http://twigerror/admin/reports

Temporary workaround:
add "twig/twig": "^1.40.0" to the conflict section of your composer.json

Steps to reproduce:

Install a new drupal with composer.

Comments

Corn696 created an issue. See original summary.

corn696’s picture

Issue summary: View changes
corn696’s picture

Issue summary: View changes
mmjvb’s picture

Priority: Critical » Normal

With such a workaround, it can't be critrical.

corn696’s picture

Matter of opinion. For the normal user who wants to try drupal this could be a reason not to use drupal.

A fresh install is not useable.

IamOnStage’s picture

I am a normal user! Where do I put this in my composer.json file please?

The specific error I am getting is:

Uncaught PHP Exception Twig\Error\SyntaxError: "An exception has been thrown during the compilation of a template ("Node "options" does not exist for Node "Drupal\Core\Template\TwigNodeTrans".") in "core/themes/stable/templates/admin/update-project-status.html.twig"." at /EXAMPLELOCATION/Website/Development/d8_dc/vendor/twig/twig/src/Environment.php line 798

This is an update from 8.6.14 to 8.6.15

IamOnStage’s picture

I am quite new to D8 (been using D7 for just the last couple of years). Is below what I should have in my composer.json?

    "conflict": {
        "drupal/drupal": "*",
        "twig/twig": "^1.40.0"
    },

Also do I need to undo the updates and then run composer update again. Or can I just run composer update after making this composer.json change and it will correct itself?

corn696’s picture

correct.

Run composer update should downgrade the package.

joseph.olstad’s picture

we are also having this problem since we did a composer require lightning_media
and we have drupal core 8.6.15

dtkweb’s picture

Currently I have solved with this composer require twig/twig:^1.39.0

matthiasm11’s picture

Used the code of #7 as a temporary solution.

cilefen’s picture

Some site administrators use https://github.com/webflo/drupal-core-strict.

rajab natshah’s picture

Confirmed I have the issue
Thanks
#7

andsigno82’s picture

#7 worked for me.
also check you have twig/twig:^1.39.0

berdir’s picture

Priority: Normal » Critical

We've treated such issues as critical before, update might be required in case of security updates for example.

I've reopened #3044155: PHP7.1 vendor max Testing issue - DO NOT COMMIT so we can catch that stuff quickly.

jcmartinez’s picture

I had this issue and #7 worked for me. Thanks!
Running composer update, I see:
- Downgrading twig/twig (v1.40.1 => v1.39.1): Loading from cache

nigelcunningham’s picture

I would also argue that it should be treated as critical. Minor version updates to Drupal core should IMHO never break a site by themselves.

The workaround will require people to remember to remove it at some stage - perhaps someone should comment here when it's safe to do so?

Hookset Media’s picture

+1 for #7 Been fighting with this all day. Lifesaver!

mmjvb’s picture

It is not a matter of opinion, it is a matter of definition: see https://www.drupal.org/core/issue-priority
Won't change it back, will wait for people with more authority.

Indeed, not the first time this happens, people do make mistakes. Normally, they learn from them when the mistake is pointed out to them. However, some just insist on repeating the mistakes.

It is not a break due to minor update of drupal core. It is a break because of a minor update in a dependency (twig) of core.
Only allowed to happen when it concerns a bugfix. Which defines the break a bug in drupal core.
So far, it is unknown what change caused this break. Which means it is not confirmed yet this is a bug in drupal core. It is still possible to be a bug in twig.

cilefen’s picture

Since people are trying to inculcate in others the benefits of building Drupal 8 sites with Composer rather than from compressed archives, the major issue priority guideline "Trigger a PHP error through the user interface, but only under rare circumstances or affecting only a small percentage of all users, even if there is a workaround" is not apt. It is reasonable to expect this will affect a large percentage of users. Plus the very similar issue I reference in the next paragraph was considered critical and no one complained. So I am ok with this being critical for now.

Furthermore I reiterate what I wrote in #13 and explain that others agree: #3039408-54: Updating twig/twig to v1.38.0 or v1.38.1 causes fatal error. Drupal core 8.6.15 ships with Twig locked to 1.38.2. If you use https://github.com/webflo/drupal-core-strict as directed you will have exactly the version shipped with Drupal.

LemonHardos’s picture

Fine with #7, thanks

larowlan’s picture

https://github.com/twigphp/Twig/pull/2949 might be the cause, given # is a special character in render arrays

warped’s picture

Since drupal-composer/drupal-project is recommended as a path to get existing sites running with composer, and that uses webflo/drupal-core-require-dev, it seems unlikely that webflo/drupal-core-strict will be the sole composer way used to update core.
Demanding use of drupal-core-strict is kind of like telling everyone to use only stable releases of modules, or not to use modules that aren't under the drupal security advisory policy. There are valid reasons to use drupal-core-require-dev, just as there are reasons to use releases of modules, other than stable.
Reducing the number of bad experiences with people of varying skills should be important.
For example, do we have daily tests running with the various beta/RC/latest releases of important 3rd party libraries that Drupal uses?
Having time to fix an issue before people run into it seems like a good use of our time, rather than the many people who waste hours or days trying to figure out what went wrong, or even worse, giving up.
Drupal is fantastic. Let's make it better.

piridium’s picture

I also came across the problem. #7 helps temporarily.

rajab natshah’s picture

Strict vs Wiled card requirements

Strict:

We will be in control

  • but too much to follow,
  • and too many releses

Wild Card:

More flexible requirements,

  • but small control over packages
  • and more fix releases
  • and we have to keep watching all updates

Tested both, but still, do not know which one is better
I like strict but it needs more work. and now working with wild card options (~) (^)

https://github.com/drupal-composer/drupal-project/blob/8.x/composer.json

Is webflo/drupal-core-strict going to be in drupal-composer/drupal-project?

vojta’s picture

I had same problem after running:

composer update --with-all-dependencies --prefer-stable
> DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 3 updates, 0 removals
  - Updating twig/twig (v1.39.1 => v1.40.0): Downloading (100%)         
  - Updating drupal/comment_notify (1.0.0-beta6 => 1.0.0-beta7): Downloading (100%)         
  - Updating stecman/symfony-console-completion (0.9.0 => 0.10.0): Downloading (100%)         
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating autoload files
> DrupalProject\composer\ScriptHandler::createRequiredFiles

Gave error

[...] [proxy_fcgi:error] [pid 26938:tid 140458293233408] [client XXX:48036] AH01071: Got error 'PHP message: Uncaught PHP Exception Twig\\Error\\SyntaxError: "An exception has been thrown during the compilation of a template ("Node "options" does not exist for Node "Drupal\\Core\\Template\\TwigNodeTrans".") in "core/themes/bartik/templates/block--system-menu-block.html.twig"." at /.../vendor/twig/twig/src/Environment.php line 798\n'

Fix suggested in #7 worked.

alexpott’s picture

Title: Update to twig 1.40.1 causes twig exceptions » Update to twig 1.40.0 causes twig exceptions

Can someone add some steps to reproduce this fail? Here's what I've tried:

  1. Running composer update twig/twig --prefer-source - this upgrade twig to 1.40.0 as expected. (I've fixed the issue title because 1.40.1 does not exist)
  2. Installing the standard profile
  3. Visiting the front page - this definitely has a menu block on for the tools menu - so the bartik template is being used.

I can't see the reported error.

What am I doing wrong?

kingdutch’s picture

@alexpott

We're getting this on a site that has interface translation enabled and the error also suggests that this happens on a trans tag. What happens if you install another language or install the site itself in a non-English language?

~ Kingdutch

corn696’s picture

Yesterday on two existing sites i run composer update --with-dependencies and got twig 1.40.1

If i installed drupal with composer yesterday. Language german profile standard got twig 1.40.1 as well.
composer create-project drupal-composer/drupal-project:8.x-dev my_site_name_dir --no-interaction

Adding twig 1.40 to conflict and composer update downgrade 1.40.1 to 1.39.1

Today if I install a new drupal with composer. I get 1.40.0

Sites that are already updated to 1.40.1 have to downgrade and run composer update again to get 1.40.0

arturopanetta’s picture

#7 Work for me. Thanks!

gábor hojtsy’s picture

@alexpott: I just installed a branch new D8 site with instructions from https://www.drupal.org/docs/develop/using-composer/using-composer-to-ins... This one line followed by setting up Drupal on the web UI in English:

composer create-project drupal-composer/drupal-project:8.x-dev my_site_name_dir --no-interaction

I get the same error:

[Mon Apr 29 11:55:20.549563 2019] [fcgid:warn] [pid 88273:tid 123145635053568] [client 127.0.0.1:49541] mod_fcgid: stderr: Uncaught PHP Exception Twig\\Error\\SyntaxError: "An exception has been thrown during the compilation of a template ("Node "options" does not exist for Node "Drupal\\Core\\Template\\TwigNodeTrans".") in "core/themes/bartik/templates/block--system-menu-block.html.twig"." at [...]/vendor/twig/twig/src/Environment.php line 798
alexpott’s picture

rar9’s picture

only #7 works for me when twig is downgrade from 1.40.0 to v1.38.4

alexpott’s picture

So running the full test infra after doing a composer update - appears to work... https://www.drupal.org/project/drupal/issues/3044155#comment-13086612 very odd.

cilefen’s picture

@RajabNatshah That’s a good question.

alexpott’s picture

Version: 8.6.15 » 8.6.x-dev
Status: Active » Needs review
StatusFileSize
new573 bytes
new2.44 KB
new1.88 KB

So this only occurs on 8.6.x and probably 8.5.x too. It's not happening on 8.7.x and 8.8.x because they have #2600154: Update our Twig code to be ready for Twig 2.x committed. Here's the part of that patch that is relevant.

alexpott’s picture

mmjvb’s picture

@RajabNatshah With Semantic Versioning in mind would suggest to go for the most conservative wild card: ~#.#.#. It would have prevented these kind of issues. It would allow for developers to decide when to support minor version of the dependency. Consider it an improvement to the current situation related to twig. ~1.37.0 || ~1.38.0 || ~1.39.0 would give the time to resolve the issue with 1.40. Obviously, it doesn't take care of the bad combinations. You might want to specify them as conflicting although they are only conflicting for limited versions.

cilefen’s picture

The last submitted patch, 37: 3040210-37-test-only.patch, failed testing. View results

cilefen’s picture

@Warped There are issues for that effort: #3044155: PHP7.1 vendor max Testing issue - DO NOT COMMIT

The last submitted patch, 37: 3040210-37-test.patch, failed testing. View results

rajab natshah’s picture

Thank you Chris, mmjvb

With (~) - current default
https://git.drupalcode.org/project/varbase_core/blob/8.x-6.12/composer.json

With (^) - old
https://git.drupalcode.org/project/varbase_core/blob/8.x-6.0/composer.json

The strict use - Very old
https://git.drupalcode.org/project/varbase/blob/8.4.20/composer.json

Now we are mixing

  • Strict for patched projects
  • ^ When we want to set a lowest version and up
  • ~ When we want to set a lowest major version

Still some time a sub package may call a new version of a sub package then we will have issues.

Only the composer.lock is our safety on install or on creating projects,
But no safety when we composer update

alexpott’s picture

StatusFileSize
new1.67 KB
new3.55 KB
new1.88 KB

Ah deprecations getting in the way....

gábor hojtsy’s picture

Title: Update to twig 1.40.0 causes twig exceptions » Updating Drupal 8.6.x to twig 1.40.0 causes twig exceptions

Let's get the minor version into the title for clarity.

jary’s picture

#7 and #8 works for me as well

The last submitted patch, 45: 3051269-45.test-only.patch, failed testing. View results

fabpot’s picture

Can anyone confirm that https://github.com/twigphp/Twig/pull/2991 fixes the issue? I've tested with a branch new Drupal installation and that seem to work for me.

waverate’s picture

Patch at #45 works. Thank you @alexpott.

shaal’s picture

Status: Needs review » Reviewed & tested by the community

Using git to download Drupal 8.6.x
Running fresh install using drush si standard the site works as expected.

After running composer update the site stopped working, and displayed an error message

The website encountered an unexpected error. Please try again later.

After applying the patch from #45, the website is loading and doesn't display any error.

I ran the same test with Umami on 8.6.x drush si demo_umami. Confirming patch #45 resolves the issue.

jjcarrion’s picture

Patch #45 works for me as well, thanks!

blacklabel_tom’s picture

Just bumped into this issue with a fresh install (playing around with commerce) patch in #45 fixed it.

alexpott’s picture

The good news is that this is being fixed upstream - a new Twig release should occur shortly - see https://github.com/twigphp/Twig/issues/2990 and https://github.com/twigphp/Twig/pull/2991 - so hopefully we won't need to do anything.

mikelutz’s picture

This should run the upstream fix against our testbot, @fabpot

mikelutz’s picture

StatusFileSize
new1.88 KB

And re-uploading #45 for the RTBC

pclaitte’s picture

New Twig release available

shaal’s picture

Status: Reviewed & tested by the community » Closed (cannot reproduce)

As @alexpott mentioned in #54, Twig version 1.40.1 was just released.

Running composer update now using Twig 1.40.1,
Drupal website is working without any patches needed.

JeisonSteven’s picture

Recently they have already launched the update to v1.40.0 => v1.40.1 that solved the problem

composer update will solve the problem by changing version v1.40.0 => v1.40.1

vojta’s picture

Yes, twig/twig v1.40.1 works well. But still, such minor update should not break the site.

berdir’s picture

> But still, such minor update should not break the site.

That's like saying "Bugs shouldn't exist.". People make mistakes, nobody broke this on purpose, it was just an oversight and the drupal and symfony comunity have worked together to fix this as fast as possible.

We are in the process of improving our testing so that we do regular tests with the most recent versions of our dependencies, but this has been fixed within 24h, much faster isn't really possible, the only option would be to test before doing releases but that's not easy, maybe in combination with rc-releases or so in twig/symfony/..., but that's not in our control.

rar9’s picture

Thanks for the Twig update fix
Reverting #7 + Composer update ... site still works

skuark’s picture

Solved with composer update twig/twig.

chi’s picture

so hopefully we won't need to do anything

We might need to bump Twig version in composer.json to "^1.40.1".

mmjvb’s picture

> But still, such minor update should not break the site.

Which is why you should add twig to your project requirements. Use ~1.40.1 as version constraint.
With twig 1.41 it will be your decision to use it.

BTW: In composer update --with-all-dependencies --prefer-stable the --with-all-dependencies doesn't make sense. Only to use it when whitelisting packages. Same thing goes for --with-dependencies.

EDIT: You might want to do that for symfony/http-foundation as well. Or create a package like webflo/drupal-core-require-dev but only for symfony/twig packages.

rajab natshah’s picture

Tested ...

The build is working now
composer update is working as well

twig/twig 1.40.1 is out
https://packagist.org/packages/twig/twig#v1.40.1

I have tested the build with the robot and it's working now
We can remove the temp fix from projects

Thanks all :)

joseph.olstad’s picture

I will remove the conflict on 1.40.0 that I put into our composer.json yesterday.
Reports are saying twig 1.40.1 fixes the bug.

Like Berdir says more frequent testing of latest dependencies will help in the future.

Thanks all!

mmjvb’s picture

Actually, you shouldn't remove the conflict on 1.40.0. You don't want that version of twig installed in your project.

ressa’s picture

I can confirm that the problem is solved. This command resulted in a Twig exception error yesterday, but works fine today:
composer update --no-dev --with-dependencies -v;

mmjvb’s picture

The --with-dependencies makes no sense, only use it when whitelisting packages.

andrimont’s picture

Hello all, I have this message. I wonder if it is related or another issue.
The site seems working from front but there is no view on the admin side.
Thank for help. I am not sure what I should do & I do not want make situation worst.

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Twig\Error\SyntaxError</em>: An exception has been thrown during the compilation of a template (&quot;Node &quot;options&quot; does not exist for Node &quot;Drupal\Core\Template\TwigNodeTrans&quot;.&quot;) in &quot;core/themes/classy/templates/views/views-mini-pager.html.twig&quot;. in <em class="placeholder">Twig\Environment-&gt;compileSource()</em> (line <em class="placeholder">798</em> of <em class="placeholder">/PATH/vendor/twig/twig/src/Environment.php</em>).
mmjvb’s picture

Sounds like you are running twig 1.40.0. If so, update to 1.40.1

andrimont’s picture

Thank you @mmjvb
I run this

composer require twig/twig:1.40.1

Is this command correct ?

mmjvb’s picture

Indeed, that will get you twig 1.40.1
Whether it is correct depends on your situation. Normally, "composer update twig/twig" would have worked as well. It doesn't add a primary requirement, it just gets you the most recent version while respecting your version constraint.

Don't know your circumstances but D8.7 is to be expected soon. It will introduce twig 2.x, so adding the requirement to 1.40.1 is not something I would do.

gábor hojtsy’s picture

Don't know your circumstances but D8.7 is to be expected soon. It will introduce twig 2.x, so adding the requirement to 1.40.1 is not something I would do.

Drupal 8.7 is backwards compatible with prior Drupal 8.x versions and therefore WILL NOT introduce Twig 2 by default. Drupal 8.7 should be fully compatible with Twig 2 and if you patch your composer files, it will be able to work with Twig 2, but in the interest of backwards compatibility that is not done by default.

andrimont’s picture

Thanks @mmjvb strangely composer require twig/twig:1.40.1 didn't bring things baks. May be this is because of some cache. I even did a drush cr.
Then, it went ok with this composer command composer require twig/twig:1.x-dev.
I could get all the views in the back-office ;-)

mgstables’s picture

Thanks @andrimont, I had the same error message and your solution was the only one that helped.

mmjvb’s picture

Strange, maybe use "(sudo) composer selfupdate" to get the most recent version.

Ran "composer update twig/twig" and that worked. Went from 1.39 to 1.40.1

Did you remove the conflict entry, unless it uses 1.40.0 without ^ in front.

There is at this moment no difference between them (1.40.1 and 1.x-dev). You might try "composer prohibits twig/twig:1.40". It should report: There is no installed package depending on "twig/twig" in versions not matching 1.40

warped’s picture

@cilefen Thanks for the link. Just felt I had to say something because of the posts that suggested everyone should use webflo/drupal-core-strict. After seeing all the posts on slack in #support, #commerce, #composer, etc. with people having issues, taking time to fix it, and others taking time to help them. Trying to help and give feedback. :D

joseph.olstad’s picture

Status: Closed (cannot reproduce) » Needs review

Patch #56 is probably maybe a good idea!?
To reproduce the failure, grab twig 1.40.0.

On the other hand, perhaps just leave this in the hands of the twig people and trust that future versions of twig will handle this.

joseph.olstad’s picture

Status: Needs review » Closed (works as designed)

works as designed with twig 1.40.1 and higher
or twig 1.39.2 and lower

andrimont’s picture

I am glad that this could help you @mgstables.
Thanks @mmjvb, I know that this strange as I understand that there was no difference between 1.40.1 and 1.x-dev at the time.
I didn't try composer update twig/twig. I also didn't know the way to check a version (with composer prohibits twig/twig:1.40). I will remember those advices if I come across something similar.

Andy_D’s picture

Status: Closed (works as designed) » Needs work

Ignore me - got issue confusion. Putting this on the correct issue now.

alexpott’s picture

@Andy_D there was a phantom version of 1.40.1 - perhaps it's that. But looking at your error it's not the same error as before - it's not our TwigNodeTrans class it's the CheckToStringNode class and it's coming from themes/custom/focusrite/components/_patterns/03-organisms/_node.twig - so i'd guess that something is not quite right in that template. Or something in the recent Twig changes has exposed something unexpected in that template.

Andy_D’s picture

Status: Needs work » Closed (works as designed)
jjwfcd’s picture

i downgrade my twig to 1.38.2 and the error gone

d.fisher’s picture

I'm still having this exact issue with core 8.7.3 and twig 1.42.1. Am I literally the only person who is still struggling with this?

d.fisher’s picture

And just like that I found the solution. If you're using a theme built on an older version of Emulsify check out this comment for the fix you need:
https://www.drupal.org/project/drupal/issues/3040269#comment-13030254