掲示板

Liferay.Loader.define of undefined

thumbnail
7年前 に John Schulz によって更新されました。

Liferay.Loader.define of undefined

New Member 投稿: 22 参加年月日: 16/07/29 最新の投稿
I'm trying to get started exposing Liferay 7 es2015 modules to other portlets by following this tutorial:
https://github.com/liferay/liferay-docs/tree/master/develop/tutorials/code/osgi/modules/js-logger


But I'm not able to blade deploy the module without removing the the module.config.generator dependency on line 17 of the build.gradle file:
classpath group: "com.liferay", name: "com.liferay.gradle.plugins.js.module.config.generator", version: "1.0.22"


Otherwise, I will get this error in Terminal after trying to blade deploy the module:

Error
  0. [ExceptionTransformer.transform] org.gradle.tooling.BuildException: Could not fetch model of type 'CustomModel' using Gradle distribution 'https://services.gradle.org/distributions/gradle-3.0-bin.zip'.


So if i remove the generator dep and deploy, then deploy a portlet that requires it with aui in the view.jsp like this:

	<aui:script require="js-logger/logger.es">
		var Logger = jsLoggerLoggerEs.default;

		var loggerOne = new Logger('*** -&gt; ');
		loggerOne.log('Hello');

		var loggerDefault = new Logger();
		loggerDefault.log('World');
	</aui:script>


I get the following error in the browser console:
Uncaught TypeError: Cannot read property 'define' of undefined



Which points to Liferay.Loader.define("js-logger@1.0.0/utils/log.es", ["exports"], function (exports) {
	"use strict";

	Object.defineProperty(exports, "__esModule", {
		value: true
	});

	exports.default = function (msg) {

		document.getElementById("context").innerHTML += msg + ' ';
	};
});
//# sourceMappingURL=log.es.js.map


What am I doing wrong???
thumbnail
7年前 に John Schulz によって更新されました。

RE: Liferay.Loader.define of undefined

New Member 投稿: 22 参加年月日: 16/07/29 最新の投稿
Please see attached js-logger module and blade.portlet.jsp modules for source code.

Thank you,
John

添付ファイル:

thumbnail
7年前 に Severin Rohner によって更新されました。

RE: Liferay.Loader.define of undefined (回答)

Junior Member 投稿: 43 参加年月日: 14/01/28 最新の投稿
Hi John
On Friday I faced the same issue. My quick workaround was to add the JavaScript
Liferay.Loader = Loader;
before I was loading the module. (With Liferay Workspace 1.2.4)
If you use Liferay Workspace 1.2.0 (file settings.gradle) the transpile code in the build folder starts with
define("js-logger@
, with version 1.2.4 it starts with
Liferay.Loader.define("js-logger@


IMHO the Liferay Workspace has implemented new "features" they aren't int Liferay 7 GA3. So hopefully there will be soon the GA4!
thumbnail
7年前 に Chema Balsas によって更新されました。

RE: Liferay.Loader.define of undefined

Regular Member 投稿: 127 参加年月日: 13/02/25 最新の投稿
Hey John, Severin,

Based on community feedback, we implemented a way to Hide Liferay's AMD Loader. To do this, we now always namespace the previously global require and define methods.

All the generated code points to the namespaced version of those methods so everything works even if the admin decides to hide it from the global scope.

This was backported and will be available as soon as GA4 is released, so in the meantime, you should use an older version of the gradle plugins or some kind of workaround as Severin pointed out.

Sorry for the inconvenience emoticon
thumbnail
7年前 に John Schulz によって更新されました。

RE: Liferay.Loader.define of undefined

New Member 投稿: 22 参加年月日: 16/07/29 最新の投稿
Thank you Severin!!!!
Lifesaver! I was honestly stuck. I appreciate the quick response.

Chema, what kind of change will be required when GA4 is released...will we simply call
Liferay.Loader.define(...)

as documented?
thumbnail
7年前 に Chema Balsas によって更新されました。

RE: Liferay.Loader.define of undefined

Regular Member 投稿: 127 参加年月日: 13/02/25 最新の投稿
Hey John,

Unless you are manually doing require or define calls, you shouldn't need to change anything. Even then, you wouldn't necessarily need to change those. If you're sure your admins will never hide the Liferay Loader, then the global methods will always be exposed.

Once GA4 is out, you can keep using the new versions of the gradle plugins normally and all the code should work for you.
thumbnail
7年前 に John Schulz によって更新されました。

RE: Liferay.Loader.define of undefined

New Member 投稿: 22 参加年月日: 16/07/29 最新の投稿
Thanks Chema!