Foros de discusión

Liferay.Loader.define of undefined

thumbnail
John Schulz, modificado hace 7 años.

Liferay.Loader.define of undefined

New Member Mensajes: 22 Fecha de incorporación: 29/07/16 Mensajes recientes
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
John Schulz, modificado hace 7 años.

RE: Liferay.Loader.define of undefined

New Member Mensajes: 22 Fecha de incorporación: 29/07/16 Mensajes recientes
Please see attached js-logger module and blade.portlet.jsp modules for source code.

Thank you,
John

Archivos adjuntos:

thumbnail
Severin Rohner, modificado hace 7 años.

RE: Liferay.Loader.define of undefined (Respuesta)

Junior Member Mensajes: 43 Fecha de incorporación: 28/01/14 Mensajes recientes
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
Chema Balsas, modificado hace 7 años.

RE: Liferay.Loader.define of undefined

Regular Member Mensajes: 127 Fecha de incorporación: 25/02/13 Mensajes recientes
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
John Schulz, modificado hace 7 años.

RE: Liferay.Loader.define of undefined

New Member Mensajes: 22 Fecha de incorporación: 29/07/16 Mensajes recientes
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
Chema Balsas, modificado hace 7 años.

RE: Liferay.Loader.define of undefined

Regular Member Mensajes: 127 Fecha de incorporación: 25/02/13 Mensajes recientes
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
John Schulz, modificado hace 7 años.

RE: Liferay.Loader.define of undefined

New Member Mensajes: 22 Fecha de incorporación: 29/07/16 Mensajes recientes
Thanks Chema!