Hello, since I updated webpack-encore I got this error when I run the compilation:
`webpackMode` expected 'lazy', 'eager' or 'weak', but received: undefined.

I do not know why.
I specify that I also had to update these packages:
file-loader: from v1 to v6
sass-loader: to v10
This is my current packages.json :
json
{
"devDependencies": {
"@symfony/stimulus-bridge": "^1.1.0",
"@symfony/ux-chartjs": "file:vendor/symfony/ux-chartjs/Resources/assets",
"@symfony/webpack-encore": "^1.0.4",
"core-js": "^3.8.3",
"regenerator-runtime": "^0.13.2",
"sass-loader": "^10.1.1",
"stimulus": "^2.0.0",
"webpack-notifier": "^1.13.0"
},
"license": "UNLICENSED",
"private": true,
"scripts": {
"dev-server": "encore dev-server",
"dev": "encore dev",
"watch": "encore dev --watch",
"build": "encore production --progress"
},
"dependencies": {
"dotenv": "^8.2.0",
"file-loader": "^6.2.0",
"node-sass": "^4.14.0",
"webpack-jquery-ui": "^2.0.1",
//...
}
}
Do you know where the problem may come from?
This seems to be a bug in how controllers.json is handled.
E.g:
"@symfony/ux-swup": {
"swup": {
"enabled": true,
"webpackMode": "eager"
}
}
On composer install with the newest 1.0.4 release the key webpackMode will be changed to fetch. This is apparently attempted each time the package is actually installed.
So even if I did the upgrade locally, installation everywhere - e.g. the CI - will fail (as the changes to this file were of course committed).
Hi everyone!
Thanks for opening this! We updated a bunch of packages all at once, and due to some breaking changes in stimulus-bridge it was difficult to get all versions to work together.
SO, this error happens if:
fetch in your controllers.json file (this replaces webpackMode in stimulus-bridge v2)@symfony/stimulus-bridge 1.x, which is confused when webpackMode is missing.So, the solution is really to upgrade to @symfony/stimulus-bridge v2. It's an easy upgrade - I have notes about it here https://symfony.com/blog/webpack-encore-1-0-and-stimulus-bridge-2-0-released#upgrading-to-stimulus-bridge-2-0
Also, the reason that you're suddenly seeing fetch in your controllers.json file when you install UX packages is that the newest version of symfony/flex uses fetch instead of webpackMode. So, there's this special "black hole" of:
A) Latest symfony/flex
B) old v1.x of @symfony/stimulus-bridge
That causes this hard-to-debug error.
Let me know if this helps!
My main problem here seems to be that a composer install always unconditionally seems to touch assets/controllers.json.
So if packages are old in vendor and composer installs all the new ones, this just failed in our CI:
Error: Undefined array key "webpackMode"
[ErrorException]
Undefined array key "webpackMode"
I have to add "webpackMode":… to allow composer install to succeed. Which will in turn always rewrite the file (and package.json, which is quite bad as is seems to conflict with npm over the line breaks at the end).
@weaverryan my proposal to allow a smoother transition was to make symfony/flex generate both fetch and webpackMode in controllers.json, so that it can be read by both versions of the bridge (which will each ignore one of the keys). Any reason why this was not implemented ?
Most helpful comment
Hi everyone!
Thanks for opening this! We updated a bunch of packages all at once, and due to some breaking changes in
stimulus-bridgeit was difficult to get all versions to work together.SO, this error happens if:
fetchin yourcontrollers.jsonfile (this replaceswebpackModeinstimulus-bridgev2)AND
@symfony/stimulus-bridge1.x, which is confused whenwebpackModeis missing.So, the solution is really to upgrade to
@symfony/stimulus-bridgev2. It's an easy upgrade - I have notes about it here https://symfony.com/blog/webpack-encore-1-0-and-stimulus-bridge-2-0-released#upgrading-to-stimulus-bridge-2-0Also, the reason that you're suddenly seeing
fetchin yourcontrollers.jsonfile when you install UX packages is that the newest version ofsymfony/flexusesfetchinstead ofwebpackMode. So, there's this special "black hole" of:A) Latest
symfony/flexB) old v1.x of
@symfony/stimulus-bridgeThat causes this hard-to-debug error.
Let me know if this helps!