IBM Worklight 6.1 - Uncaught ReferenceErrors: WLJQ

2019-05-10 08:38发布

问题:

I'm using IBM Worklight Developer Edition 6.1 installed in Eclipse Juno as my IDE and backbonejs as my main javascript framework for my project.

My index.html

<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
    <script>window.$ = window.jQuery = WLJQ;</script>

    <script data-main="js/main" src="js/libs/require/require.js"></script>
</head>
<body>

</body>
</html>

My main.js

require.config({
    paths: {
        jquery: 'libs/jquery/jquery-min',
        underscore: 'libs/underscore/underscore-min',
        backbone: 'libs/backbone/backbone-min',
        templates: '../templates',
        bootstrap: 'bootstrap.min',
        initOptions: 'initOptions',
        biiRibMobile: 'biiRibMobile',
        messages: 'messages'
    },
});
require(['app', ], function(App) {
    App.initialize();
});

My app.js

// Filename: app.js
define(['jquery', 'underscore', 'backbone', 'router', // Request router.js
'bootstrap', 'initOptions', 'biiRibMobile', 'messages', ], function($, _, Backbone, Router, bootstrap, initOptions, biiRibMobile, messages) {
    var initialize = function() {
            // Pass in our Router module and call it's initialize function
            Router.initialize();
        };
    return {
        initialize: initialize
    };
});

My initOptions.js

var wlInitOptions = {

    logger : {enabled: true, level: 'debug', stringify: true, pretty: false,
        tag: {level: false, pkg: true}, whitelist: [], blacklist: []},

    analytics : {
        enabled: false
        //url : ''
    }

};

if (window.addEventListener) {
    window.addEventListener('load', function() { WL.Client.init(wlInitOptions); }, false);
} else if (window.attachEvent) {
    window.attachEvent('onload',  function() { WL.Client.init(wlInitOptions); });
}

Thanks a lot in advance.

回答1:

@DavidDhuyveter has a good answer in the comments. I had this problem on a Mac and on a Windows PC. His answer fixed my Mac issues.

For Windows, the temp folder should be in /Users/you/AppData/Local/Temp/1/ or something along those lines.

EDIT David comments were deleted. This is the original:

If you are on a mac, do the following: Exit eclipse. Open a terminal window and cd $TMPDIR, rm -rf wlBuildResources wlPreview, Restart Eclipse, rebuild your app and you should be good to go –



回答2:

This problem actually happens a lot and it is actually really frustrating. Sometimes everything will be working for awhile and out of nowhere, this lovely error pops up. Something you can do instead (which has worked for me consistently) is:

  1. In Eclipse, go to Project -> Clean ...
  2. Select clean selected project checkbox, and select your Project
  3. Hit ok

I would try that first and see what it does. If not, you can do the trusted method of removing and re-importing.



回答3:

This problem still occurs in v7.0.

While the cleaning of the TMPDIR works some times, it does not always do so - I can see no pattern here.

Rebooting my MACbook seems to work reliably, I speculate that this is because we get a new TMPDIR.

I just discovered that:

  1. Remove project from server
  2. Rename project (eg MyProjectZZZ)
  3. Rebuild and deploy, but don't bother to run
  4. Rename project back to MyProject
  5. Rebuild and deploy

Seems to clean things up



回答4:

What helps me each time when I run into this problem while opening the app from the Worklight console is that I right-click on the app, choose Run As -> Preview before I attempt to load it from the Worklight console. After that, app starts working no matter from where I launch it.



回答5:

same problem with WL 6.1.My app did not work with the link "preview as common ressources", but it worked with the mobile browser simulator

I Solved it by exiting eclipse then deleted wlbuildressources and wlpreview folder in tmp folder (/tmp on linux). After that, I restarted eclipse and it worked. However, it is a bug in 6.1.



回答6:

I think I finally figured out an easy workaround for this one.

Right click on your project name in Eclipse, choose Close Project and then right-click again and choose Open Project. This fixed my broken preview pages.



回答7:

The quickest workaround for me is to remove the project and then add the project into the workspace again. This need not suffer from renaming the project or other process.