Wirejs and dojo using the dojo build system (2)

(This is the same question as wirejs and dojo using the dojo build system , but with more detailed information about the problem and proven solutions. The question is created because it was suggested in the comment).

When creating a dojo application using explorer, the dojo loader throws an error undefinedModulefor "./lib/context", which we cannot get rid of.

I added wirea dojo to the big working project using the git submodule. It turned out that cujojs whenand cujojs are also required meld. I added them as a submodule of git.

In this project, libraries are not located next to the application folder ( src/app), but at the same level, in src/lib. Thus, I have src/lib/wire, src/lib/when, src/lib/meld, next to src/lib/dgrid, etc. <2 β†’ Library are 2 levels of depth: src/lib/dojo/dojo, src/lib/dojo/dijit, src/lib/dojo/dojoxand src/lib/dojo/util.

Versions:

  • dojo 1.10.4
  • wire 0.10.9
  • when 3.7.2
  • meld 1.3.1

Things work in development (unbuild) as soon as I add the following package definitions to dojoConfig:

var dojoConfig = (function() {

  [...]

  return {

    [...]

    packages: [

      [...]

      {name: "wire", location: "../../wire", main: "wire"},
      {name: "when", location: "../../when", main: "when" },
      {name: "meld", location: "../../meld", main: "meld" },

      [...]

    ],

    [...]
  };

})();

Please note that you must add entries main. This allows, for example, to refer to when/when.jsonce "when"in the list of dependencies instead "when/when", which cujojs code does internally.

So this works in development mode.

Then I tried to make the assembly work.

build.profile.js . .

-, dojo package.json dojoBuild, <mypackage>.profile.js package.js, . ( ) - resourceTags, , , AMD , .

cujojs , dojo.

, , -, AMD ( ).

, , dojoBuild cujojs, .

dojo , package.json, dojoBuild, , , , resourceTags, . , , resourceTags :

[...]

/*
 wire, when and meld don't have a good build profile set up.
 Here, we doctor a resourceTags (i.e., the core of a build profile). We set it on the package definition.
 This is an unsupported hack. The builder will still complain about there not being a build profile, but
 it will use these definitions when building those packages.

 Note: // see https://github.com/cujojs/when/wiki/Using-with-Dojo does not work!
*/
var generalResourceTags = (function () {

  function isTest(filename, mid) {
    return filename.indexOf("test/") >= 0;
  }

  function isCopyOnly(filename, mid) {
    return filename.indexOf(".html") >= 0;
  }

  function isAmd(filename, mid) {
    return filename.indexOf(".json") < 0 && filename.indexOf(".js") >= 0 && filename.indexOf(".profile.js") < 0;
  }

  function isGivingTroubleButUnused(filename, mid) {
    return /^wire\/jquery\//.test(mid) ||
           mid === "wire/sizzle" ||
           /^when\/build\//.test(mid) ||
           /^when\/es6-shim\//.test(mid) ||
           mid === "when/generator"; // see https://github.com/cujojs/when/issues/429
  }

  return {
    test: function (filename, mid) {
      return isTest(filename, mid);
    },

    copyOnly: function (filename, mid) {
      return isCopyOnly(filename, mid) || isGivingTroubleButUnused(filename, mid);
    },

    amd: function (filename, mid) {
      return !isTest(filename, mid) && !isCopyOnly(filename, mid) && isAmd(filename, mid) && !isGivingTroubleButUnused(filename, mid);
    }
  }
})();

var profile = {
  releaseName: releaseName,
  releaseDir: "../../../../release",
  action: 'release',
  cssOptimize: 'comments',
  mini: true,
  optimize: 'closure',
  layerOptimize: 'closure',
  stripConsole: 'normal',
  selectorEngine: 'acme',
  useSourceMaps: false,

  [...]  

  packages: [

    [...]

    {name: "wire", location: "../../wire", main: "wire", destLocation: "./lib/wire", resourceTags: generalResourceTags},
    {name: "when", location: "../../when", main: "when", destLocation: "./lib/when", resourceTags: generalResourceTags},
    {name: "meld", location: "../../meld", main: "meld", destLocation: "./lib/meld", resourceTags: generalResourceTags},

    [...]

  ],
  layers: {

    [...]

  },
  staticHasFeatures: {
    "config-publishRequireResult": false,
    "dijit-legacy-requires": false,
    "dojo-debug-messages": false,
    "dojo-firebug": false,
    "dojo-log-api": 0,
    "dojo-mobile-parser": false,
    "dojo-moduleUrl": false,
    "dojo-parser": true,
    "dojo-publish-privates": 0,
    "dojo-test-sniff": 0,
    "dojo-trace-api": 0,
    "dom-addeventlistener": true,
    "extend-dojo": true,
    "host-browser": true,
    "mvc-bindings-log-api": false,

    [...]

  }
};

resourceTags wire, when meld. "" , generalResourceTags. resourceTags, isGivingTroubleButUnused, .

, , https://github.com/cujojs/when/wiki/Using-with-Dojo when, .

, dojo, . , jquery. .

, , wirejs dojo dojo, , packageJson. .

, isGivingTroubleButUnused, , . , 1 when/generator. Closure (. https://github.com/cujojs/when/issues/429).

.

... . , , dojo, undefinedModule Error "./lib/context". , 23 wire/wire.js:

createContext = require('./lib/context');

wire/lib/context.js, , , (unbuild).

require - (. dojotoolkit.org/documentation/tutorials/1.10/modules_advanced/, " " ), . , .

wire, when meld. dojo, async. , :

var generalResourceTags = (function () {

  function isTest(filename, mid) {
    return filename.indexOf("test/") >= 0;
  }

  [...]

  return {
    test: function (filename, mid) {
      return isTest(filename, mid);
    },

    copyOnly: function (filename, mid) {
      return !isTest(filename, mid);
    },

    amd: function (filename, mid) {
      return false;
    }
  }
})();

, . , , wire, (error(311) Missing dependency. module: MY_MODULE; dependency: wire!SOME_PACKAGE/_wire-serverRequests).

, , : undefinedModule Error "./lib/context".

, , wire require, - , unbuild.

. -, wire ,

createContext = require('wire/lib/context');

. .

sourceMaps (useSourceMaps = true). , , , require , -.

, " "? , HTML,

require(["wire/lib/context"], function() {

  [...]

});

, context , - . .

Then I added an entry to the code in wire/lib/context

console.error("Defining context");

var when, mixin, loaderAdapter, relativeLoader, Container, specUtils;

when = require('when');
console.error("Loaded when");
mixin = require('./object').mixin;
console.error("Loaded ./object");
loaderAdapter = require('./loader/adapter');
console.error("Loaded ./loader/adapter");
relativeLoader = require('./loader/relative');
console.error("Loaded ./loader/relative");
Container = require('./Container');
console.error("Loaded ./Container");
specUtils = require('./specUtils');

console.error("Defined context. Returning.");

(using Errorbecause other messages are deleted in the assembly).

In the unbuild version, I see all the messages. In the build version, I see only "Context Definition" before an error occurs. Therefore, the problem is not in the β€œboot” wire/lib/context, but in the definition of it and, possibly, in the download or definition when!

So I applied the same trick to when

console.error("Defining when");

var timed = require('./lib/decorators/timed');
console.error("Loaded lib/decorators/timed");
var array = require('./lib/decorators/array');
console.error("Loaded lib/decorators/array");
var flow = require('./lib/decorators/flow');
console.error("Loaded lib/decorators/flow");
var fold = require('./lib/decorators/fold');
console.error("Loaded lib/decorators/fold");
var inspect = require('./lib/decorators/inspect');
console.error("Loaded lib/decorators/inspect");
var generate = require('./lib/decorators/iterate');
console.error("Loaded lib/decorators/iterate");
var progress = require('./lib/decorators/progress');
console.error("Loaded lib/decorators/progress");
var withThis = require('./lib/decorators/with');
console.error("Loaded lib/decorators/with");
var unhandledRejection = require('./lib/decorators/unhandledRejection');
console.error("Loaded lib/decorators/unhandledRejection");
var TimeoutError = require('./lib/TimeoutError');
console.error("Loaded lib/TimeoutError");
[...]

Now there is a surprise in the unbuild version . Output:

Defining when
Loaded lib/decorators/timed
Loaded lib/decorators/array
Loaded lib/decorators/flow
Loaded lib/decorators/fold
Loaded lib/decorators/inspect
Loaded lib/decorators/iterate
Loaded lib/decorators/progress
Loaded lib/decorators/with
Loaded lib/decorators/unhandledRejection
Loaded lib/TimeoutError
Loaded lib/Promise
Loaded lib/apply
Defined when
Defining context
Loaded when
Loaded ./object
Loaded ./loader/adapter
Loaded ./loader/relative
Loaded ./Container
Defined context. Returning.

This means that the determination whenbegan before the determination context. This is strange because I do not see code that can tell the loader what whenis required in contextfront of the line

when = require('when');
Performed

which appears after the "Context Definition" logging.

In the build version, we still get

Defining context

! !

. Unbuild , .

wire , .

, -, ...

+4

All Articles