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.
| Comment | File | Size | Author |
|---|---|---|---|
| #56 | 3051269-45.patch | 1.88 KB | mikelutz |
| #55 | 3051269-55.drupal.UPSTREAM_FIX_TEST.patch | 2.76 KB | mikelutz |
| #55 | 3051269-55.drupal.BASELINE_FAIL_TEST.patch | 2.71 KB | mikelutz |
Comments
Comment #2
corn696Comment #3
corn696Comment #4
mmjvb commentedWith such a workaround, it can't be critrical.
Comment #5
corn696Matter 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.
Comment #6
IamOnStage commentedI am a normal user! Where do I put this in my composer.json file please?
The specific error I am getting is:
This is an update from 8.6.14 to 8.6.15
Comment #7
IamOnStage commentedI 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?
Also do I need to undo the updates and then run
composer updateagain. Or can I just runcomposer updateafter making this composer.json change and it will correct itself?Comment #8
corn696correct.
Run
composer updateshould downgrade the package.Comment #9
joseph.olstadwe are also having this problem since we did a composer require lightning_media
and we have drupal core 8.6.15
Comment #10
dtkweb commentedCurrently I have solved with this
composer require twig/twig:^1.39.0Comment #11
cilefen commentedComment #12
matthiasm11 commentedUsed the code of #7 as a temporary solution.
Comment #13
cilefen commentedSome site administrators use https://github.com/webflo/drupal-core-strict.
Comment #14
rajab natshahConfirmed I have the issue
Thanks
#7
Comment #15
andsigno82 commented#7 worked for me.
also check you have
twig/twig:^1.39.0Comment #16
berdirWe'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.
Comment #17
jcmartinezI 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 cacheComment #18
nigelcunningham commentedI 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?
Comment #19
Hookset Media commented+1 for #7 Been fighting with this all day. Lifesaver!
Comment #20
mmjvb commentedIt 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.
Comment #21
cilefen commentedSince 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.
Comment #22
LemonHardos commentedFine with #7, thanks
Comment #23
larowlanhttps://github.com/twigphp/Twig/pull/2949 might be the cause, given # is a special character in render arrays
Comment #24
warped commentedSince 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.
Comment #25
piridium commentedI also came across the problem. #7 helps temporarily.
Comment #26
rajab natshahStrict vs Wiled card requirements
Strict:
We will be in control
Wild Card:
More flexible requirements,
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?
Comment #27
vojta commentedI had same problem after running:
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.
Comment #28
alexpottCan someone add some steps to reproduce this fail? Here's what I've tried:
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)I can't see the reported error.
What am I doing wrong?
Comment #29
kingdutch@alexpott
We're getting this on a site that has interface translation enabled and the error also suggests that this happens on a
transtag. What happens if you install another language or install the site itself in a non-English language?~ Kingdutch
Comment #30
corn696Yesterday on two existing sites i run
composer update --with-dependenciesand got twig 1.40.1If i installed drupal with composer yesterday.
Language germanprofile standardgot twig 1.40.1 as well.composer create-project drupal-composer/drupal-project:8.x-dev my_site_name_dir --no-interactionAdding twig 1.40 to conflict and
composer updatedowngrade 1.40.1 to 1.39.1Today 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 updateagain to get 1.40.0Comment #31
arturopanetta#7 Work for me. Thanks!
Comment #32
gábor hojtsy@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-interactionI get the same error:
Comment #33
alexpottThere was a phantom tag... https://github.com/twigphp/Twig/issues/2989
Comment #34
rar9 commentedonly #7 works for me when twig is downgrade from 1.40.0 to v1.38.4
Comment #35
alexpottSo 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.
Comment #36
cilefen commented@RajabNatshah That’s a good question.
Comment #37
alexpottSo 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.
Comment #38
alexpottThe breaking commit in twig/twig is https://github.com/twigphp/Twig/commit/bf3781c9c1fc678110d5f4e5659d0d70c...
Comment #39
mmjvb commented@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.
Comment #40
cilefen commented@RajabNatshah https://github.com/drupal-composer/drupal-project/issues/477
Comment #42
cilefen commented@Warped There are issues for that effort: #3044155: PHP7.1 vendor max Testing issue - DO NOT COMMIT
Comment #44
rajab natshahThank 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
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
Comment #45
alexpottAh deprecations getting in the way....
Comment #46
gábor hojtsyLet's get the minor version into the title for clarity.
Comment #47
jary commented#7 and #8 works for me as well
Comment #49
fabpot commentedCan 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.
Comment #50
waverate commentedPatch at #45 works. Thank you @alexpott.
Comment #51
shaalUsing git to download Drupal 8.6.x
Running fresh install using
drush si standardthe site works as expected.After running
composer updatethe site stopped working, and displayed an error messageAfter 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.Comment #52
jjcarrionPatch #45 works for me as well, thanks!
Comment #53
blacklabel_tom commentedJust bumped into this issue with a fresh install (playing around with commerce) patch in #45 fixed it.
Comment #54
alexpottThe 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.
Comment #55
mikelutzThis should run the upstream fix against our testbot, @fabpot
Comment #56
mikelutzAnd re-uploading #45 for the RTBC
Comment #57
pclaitte commentedNew Twig release available
Comment #58
shaalAs @alexpott mentioned in #54, Twig version 1.40.1 was just released.
Running
composer updatenow using Twig 1.40.1,Drupal website is working without any patches needed.
Comment #59
JeisonSteven commentedRecently 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
Comment #60
vojta commentedYes, twig/twig v1.40.1 works well. But still, such minor update should not break the site.
Comment #61
berdir> 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.
Comment #62
rar9 commentedThanks for the Twig update fix
Reverting #7 + Composer update ... site still works
Comment #63
skuark commentedSolved with
composer update twig/twig.Comment #64
chi commentedWe might need to bump Twig version in composer.json to "^1.40.1".
Comment #65
mmjvb commented> 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-stablethe --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.
Comment #66
rajab natshahTested ...
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 :)
Comment #67
joseph.olstadI 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!
Comment #68
mmjvb commentedActually, you shouldn't remove the conflict on 1.40.0. You don't want that version of twig installed in your project.
Comment #69
ressaI 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;Comment #70
mmjvb commentedThe --with-dependencies makes no sense, only use it when whitelisting packages.
Comment #71
andrimont commentedHello 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.
Comment #72
mmjvb commentedSounds like you are running twig 1.40.0. If so, update to 1.40.1
Comment #73
andrimont commentedThank you @mmjvb
I run this
Is this command correct ?
Comment #74
mmjvb commentedIndeed, 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.
Comment #75
gábor hojtsyDrupal 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.
Comment #76
andrimont commentedThanks @mmjvb strangely
composer require twig/twig:1.40.1didn't bring things baks. May be this is because of some cache. I even did adrush 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 ;-)
Comment #77
mgstablesThanks @andrimont, I had the same error message and your solution was the only one that helped.
Comment #78
mmjvb commentedStrange, 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
Comment #79
warped commented@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
Comment #80
joseph.olstadPatch #56 is
probablymaybe 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.
Comment #81
joseph.olstadworks as designed with twig 1.40.1 and higher
or twig 1.39.2 and lower
Comment #82
andrimont commentedI 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 (withcomposer prohibits twig/twig:1.40). I will remember those advices if I come across something similar.Comment #83
Andy_D commentedIgnore me - got issue confusion. Putting this on the correct issue now.
Comment #84
alexpott@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.
Comment #85
Andy_D commentedComment #86
jjwfcd commentedi downgrade my twig to 1.38.2 and the error gone
Comment #87
d.fisher commentedI'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?
Comment #88
d.fisher commentedAnd 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