cram buile "requires ("xxx") stops build

49 views
Skip to first unread message

Daniel Haag

unread,
Feb 25, 2013, 2:17:30 AM2/25/13
to cuj...@googlegroups.com
A pattern like requires("xxx") causes cram to stop the build
 
module.exports = function ( _ ) {
_ = _ || require("underscore");
return factory( _ );
 
changing the code to the following fixes the problem but of course is undesirable in code libraries
 
module.exports = function ( _ ) {
 _ = _ || require(["underscore"]);
return factory( _ );
 
 I am running cram on solaris 10 with node.js 0.8.20. 
I can provide a demo project showing this issue with postal.js. If I shall send it to you please drop me a note.

Regards, Daniel


unscriptable

unread,
Feb 25, 2013, 10:44:30 AM2/25/13
to cuj...@googlegroups.com
Hey Daniel,

Can you provide a more complete module?  If you have the time, can you create a minimum test case?  In other words: what is the smallest module and/or project that can simulate this problem?

This looks like a CommonJS module.  Is that true?  Or did you just skip the define() boilerplate?

If this is a CommonJS module, did you specify the cjsm11 moduleLoader in the package config?

Thanks!

-- John

Daniel Haag

unread,
Feb 25, 2013, 11:07:38 AM2/25/13
to cuj...@googlegroups.com
Hi John, thanks for your immedeate reply.

Here is how you can reproduce it:

I changed test/tiny-run.js from cram-dev like this:
define(function () {

var config = {
baseUrl: '',
paths: {
curl: './support/curl/src/curl',
underscore : '../app/js/lo-dash/lodash',
"test-js": 'test'
},
packages : [
            {name : 'postal', location : '../app/js/postal/lib', main : 'postal'},
],
pluginPath: 'curl/plugin'
};

curl(config, ['postal']).then(
function () {
setPageState('loaded');
// this should never get called by cram:
curl(['some/other/module']);
},
function () {
setPageState('failed');
}
);


// do something DOM-ish (this code should never execute during build!)
function setPageState (stateClass) {
var root = document.documentElement;
root.className = root.className.replace(/loading/, '')
+ ' ' + stateClass;
}

});

and then i added postal js relative to your cram-dev directory ../app/js/postal/lib
then i added lodash 1.0.0.rc3 relative to your cram-dev directory ../app/js/lo-dash/lodash

I have a zipped version of the cram-dev branch showing the issue. I will send it to the group email address.

Regards, Daniel

unscriptable

unread,
Feb 25, 2013, 11:47:04 AM2/25/13
to cuj...@googlegroups.com
Ah ha!  I see the problem.  Postal.js prefers CommonJS Modules to AMD modules.  

Do this:

{name : 'postal', location : '../app/js/postal/lib', main : 'postal', config: { moduleLoader: 'curl/loader/cjsm11' }

This tells curl and cram to treat postal.js ss a CommonJS Module/1.1, not an AMD module.  

OT: was cram.js displaying an error message?  If not, I'll log a bug.

Thanks!

unscriptable

unread,
Feb 25, 2013, 11:56:09 AM2/25/13
to cuj...@googlegroups.com
Even if specifying that the module is CJS instead of AMD fixes the problem, there is a deeper one.  That module should never have been evaluated.  cram.js should have loaded it as text.  I'll dig a bit deeper.

Daniel Haag

unread,
Mar 6, 2013, 2:34:40 AM3/6/13
to cuj...@googlegroups.com
I forgot Tor add Thema error. It is:
Error: sync require() found in the global scope or in an external factory.

unscriptable

unread,
Mar 6, 2013, 8:54:57 AM3/6/13
to cuj...@googlegroups.com
Ah ha!  That error makes sense to me. 

Do you still see the error after using the package config I suggested?

-- J

unscriptable

unread,
Mar 6, 2013, 9:46:12 AM3/6/13
to cuj...@googlegroups.com
The latest code in the cram.js dev branch will now warn when it finds a sync require() in the global scope, rather than throw.

The dojo/io/script issue is more complex due to an issue in curl.js dealing with circular dependencies.  You can try to work-around dojo's dojo/dom-* circular dependency by putting one of the affected modules before dojo/io/script. For instance, try putting dojo/dom-construct or dojo/dom-attr in the curl() call.  This has worked for me in the past.

-- John
Reply all
Reply to author
Forward
0 new messages