Opened 7 years ago

Closed 6 years ago

#15146 closed defect (worksforme)

Missing dependency when building a module that contains context sensitive require

Reported by: sprabhal Owned by: Rawld Gill
Priority: high Milestone: 1.9
Component: BuildSystem Version: 1.7.1
Keywords: Cc:
Blocked By: Blocking:

Description

When a module containing a context-sensitive require as mentioned in https://dojotoolkit.org/reference-guide/1.7/loader/amd.html#context-sensitive-require is built, it results in a missing dependency error during runtime. Everything works fine in the non-built version.

I did see a comment "require must not have relative mids" in util/build/transforms/depsScan.js. Does that mean context-sensitive require can never be built.

Change History (6)

comment:1 Changed 7 years ago by ben hockey

Owner: changed from Rawld Gill to sprabhal
Status: newpending

most likely you do not have require as a dependency in your module

define(['require'], function (require) {
    var foo = require('./foo'),
        bar = require('./bar');

    // ...
});

can you provide a sample of the code that fails?

comment:2 Changed 7 years ago by sprabhal

Status: pendingnew
define([
	"require",
	"dojo/_base/declare"
], function (require, declare) {
	return declare(null, {
		constructor: function () {
			//constructor
		},
		
		foo: function () {
			require([
			     "./foo",
			     "./bar"
			], function (foo, bar) {
				var fooCopy = foo;
				var barCopy = bar;
				//some operation
			});
		}
	});
});
Last edited 7 years ago by sprabhal (previous) (diff)

comment:3 in reply to:  1 Changed 7 years ago by sprabhal

define([
        "require",
        "dojo/_base/declare"
], function (require, declare) {
        return declare(null, {
                constructor: function () {
                        //constructor
                },
                
                foo: function () {
                        require([
                             "./foo",
                             "./bar"
                        ], function (foo, bar) {
                                var fooCopy = foo;
                                var barCopy = bar;
                                //some operation
                        });
                }
        });
});

Replying to neonstalwart:

most likely you do not have require as a dependency in your module

define(['require'], function (require) {
    var foo = require('./foo'),
        bar = require('./bar');

    // ...
});

can you provide a sample of the code that fails?

comment:4 Changed 6 years ago by dylan

Milestone: tbd1.9
Priority: undecidedhigh

If this is still an issue, it's kind of a big one.

Can we review and fix for 1.9, if it's an issue?

comment:5 Changed 6 years ago by dylan

Owner: changed from sprabhal to Rawld Gill
Status: newassigned

comment:6 Changed 6 years ago by ben hockey

Resolution: worksforme
Status: assignedclosed

this is working as designed. using require that way is how you lazy-load other layers after a build. leaving those dependencies out is supposed to happen. if they need to be in the same layer then add them as dependencies in the call to define for this module.

Note: See TracTickets for help on using tickets.