I'm having an issue with getting ResourceLoader to properly load the Masonry library [1]. This issue was not present on MW 1.25 but is on MW 1.27. If I do the following:
$out->addModules( 'ext.masonrymainpage.libs' ); // or as dependency to base $out->addModules( 'ext.masonrymainpage.base' );
Then I get the following error in my browser:
Uncaught Error: Module "jquery" is not loaded. at require (load.php?debug=true&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=ciafJ7Ly:12581) at masonry.pkgd.js?c5dde:29 at masonry.pkgd.js?c5dde:39 require @ load.php?debug=true&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=ciafJ7Ly:12581 (anonymous) @ masonry.pkgd.js?c5dde:29 (anonymous) @ masonry.pkgd.js?c5dde:39 load.php?debug=true&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=ciafJ7Ly:11145 Use of "wgCategories" is deprecated. Use mw.config instead. get @ load.php?debug=true&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=ciafJ7Ly:11145 (anonymous) @ load.php?debug=true&lang=en&modules=site&only=scripts&skin=vector&version=680c78b07fb0:273
However, if I load Masonry not from the ext.masonrymainpage.libs module, but instead using OutputPage::addScript() then I have no issues:
global $wgServer, $wgExtensionAssetsPath; $scriptURL = "$wgServer/$wgExtensionAssetsPath/MasonryMainPage/masonry.pkgd.js"; $out->addScript( "<script type='text/javascript' src='$scriptURL'></script>" ); $out->addModules( 'ext.masonrymainpage.base' );
Can anyone help me figure out how to do this the right way?
Thanks, James
Hi,
On 04/17/2017 02:17 PM, James Montalvo wrote:
Uncaught Error: Module "jquery" is not loaded.
Does your module definition have a dependency on 'jquery'? You should remove that as it will cause errors like this. jQuery is always loaded before any other RL modules are.
-- Legoktm
No jquery dependency specified. I put together a minimal extension to demonstrate the issue. Below is a link to the comparison of the first commit (using ResourceLoader) and the second (using OutputPage::addScript).
https://github.com/jamesmontalvo3/JustMasonry/compare/ResourceLoader...addSc...
On the `ResourceLoader` branch I get the 'Module "jquery" is not loaded' error. On the `addScript` branch I do not, and I'm able to use the library like:
var test = new Masonry("#bodyContent");
OS: CentOS Linux release 7.3.1611
Installed software: MediaWiki 1.27.2 (1c409c5) PHP 5.6.30 (apache2handler) MariaDB 5.5.52-MariaDB ICU 50.1.2
Skins: Vector – (d11a80a) 12:02, 19 May 2016
Extensions: JustMasonry 2017.4.18 (68bcd0a) 17:47, 18 April 2017 I removed all other extensions and confirmed this is still an issue.
Thanks, James
On Tue, Apr 18, 2017 at 1:51 PM, Legoktm legoktm.wikipedia@gmail.com wrote:
Hi,
On 04/17/2017 02:17 PM, James Montalvo wrote:
Uncaught Error: Module "jquery" is not loaded.
Does your module definition have a dependency on 'jquery'? You should remove that as it will cause errors like this. jQuery is always loaded before any other RL modules are.
-- Legoktm
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
The error string "Module "jquery" is not loaded" actually comes from mw.loader.require, unlike the "Unknown dependency: jquery" error which can come from mw.loader.load.
It looks like the "masonry.pkgd.js" script is detecting a CommonJS-compatible environment and therefore assumes jQuery must also be available through require().
ResourceLoader in MediaWiki only recently added support for module.exports and require. While it is available, it is not yet the default for most modules, including jQuery. However, this assumption is reasonable and actually fairly common in libraries so we should definitely add support for it. Either that, or we need a way for registered modules to opt-out of having require/module.exports available, so that libraries such as these can be loaded without problem.
-- Timo
On Tue, Apr 18, 2017 at 4:04 PM, James Montalvo jamesmontalvo3@gmail.com wrote:
No jquery dependency specified. I put together a minimal extension to demonstrate the issue. Below is a link to the comparison of the first commit (using ResourceLoader) and the second (using OutputPage::addScript).
https://github.com/jamesmontalvo3/JustMasonry/compare/ResourceLoader... addScript
On the `ResourceLoader` branch I get the 'Module "jquery" is not loaded' error. On the `addScript` branch I do not, and I'm able to use the library like:
var test = new Masonry("#bodyContent");
OS: CentOS Linux release 7.3.1611
Installed software: MediaWiki 1.27.2 (1c409c5) PHP 5.6.30 (apache2handler) MariaDB 5.5.52-MariaDB ICU 50.1.2
Skins: Vector – (d11a80a) 12:02, 19 May 2016
Extensions: JustMasonry 2017.4.18 (68bcd0a) 17:47, 18 April 2017 I removed all other extensions and confirmed this is still an issue.
Thanks, James
On Tue, Apr 18, 2017 at 1:51 PM, Legoktm legoktm.wikipedia@gmail.com wrote:
Hi,
On 04/17/2017 02:17 PM, James Montalvo wrote:
Uncaught Error: Module "jquery" is not loaded.
Does your module definition have a dependency on 'jquery'? You should remove that as it will cause errors like this. jQuery is always loaded before any other RL modules are.
-- Legoktm
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Is there a phabricator task to track this?
On Tue, Apr 18, 2017 at 7:07 PM, Krinkle krinklemail@gmail.com wrote:
The error string "Module "jquery" is not loaded" actually comes from mw.loader.require, unlike the "Unknown dependency: jquery" error which can come from mw.loader.load.
It looks like the "masonry.pkgd.js" script is detecting a CommonJS-compatible environment and therefore assumes jQuery must also be available through require().
ResourceLoader in MediaWiki only recently added support for module.exports and require. While it is available, it is not yet the default for most modules, including jQuery. However, this assumption is reasonable and actually fairly common in libraries so we should definitely add support for it. Either that, or we need a way for registered modules to opt-out of having require/module.exports available, so that libraries such as these can be loaded without problem.
-- Timo
On Tue, Apr 18, 2017 at 4:04 PM, James Montalvo jamesmontalvo3@gmail.com wrote:
No jquery dependency specified. I put together a minimal extension to demonstrate the issue. Below is a link to the comparison of the first commit (using ResourceLoader) and the second (using
OutputPage::addScript).
https://github.com/jamesmontalvo3/JustMasonry/compare/ResourceLoader... addScript
On the `ResourceLoader` branch I get the 'Module "jquery" is not loaded' error. On the `addScript` branch I do not, and I'm able to use the
library
like:
var test = new Masonry("#bodyContent");
OS: CentOS Linux release 7.3.1611
Installed software: MediaWiki 1.27.2 (1c409c5) PHP 5.6.30 (apache2handler) MariaDB 5.5.52-MariaDB ICU 50.1.2
Skins: Vector – (d11a80a) 12:02, 19 May 2016
Extensions: JustMasonry 2017.4.18 (68bcd0a) 17:47, 18 April 2017 I removed all other extensions and confirmed this is still an issue.
Thanks, James
On Tue, Apr 18, 2017 at 1:51 PM, Legoktm legoktm.wikipedia@gmail.com wrote:
Hi,
On 04/17/2017 02:17 PM, James Montalvo wrote:
Uncaught Error: Module "jquery" is not loaded.
Does your module definition have a dependency on 'jquery'? You should remove that as it will cause errors like this. jQuery is always loaded before any other RL modules are.
-- Legoktm
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
wikitech-l@lists.wikimedia.org