AMD define call does not work with RequireJS
It is possible this does not work with other amd libraries.
Passing null as the second parameter to define does not define the module with RequireJS. The following works for me in RequireJS 1.0.8 and RequireJS 2.0.1:
define('underscore.string', _s);
I am also running into the same problem. Can we get a confirm whether or not there will be a fix? Require JS 1.0.8.
I think the problem is because of then null used in the define. (RequireJS 1.0.8)
define = function (name, deps, callback) {
var node, context;
//Allow for anonymous functions
if (typeof name !== 'string') {
//Adjust args appropriately
callback = deps;
deps = name;
name = null;
}
//This module may not have dependencies
if (!isArray(deps)) {
callback = deps;
deps = [];
}
...
If you look, since null is not an array, it is basically assuming null is the callback. Should change to use define(function() { }); or define("underscore.string", [], function() {});
I guess this fix is not uploaded to the official website. Look: http://epeli.github.com/underscore.string/lib/underscore.string.js
I took a time to figure out what was happening.
I use requirejs 2.02 and shim.. but can't make the package to load..? Any idea?
require.config({
baseUrl:'.',
paths: {
underscore: 'underscore-min',
underscore_string: 'underscore.string.min'
},
shim: {
underscore_string: {
deps: ['underscore'],
exports: '_s'
},
underscore: {
exports: '_'
}
}
});
define(['underscore', 'underscore_string'], function () {
console.log ('See if we can use _s', _s)
});
I'm having the same issue…I can't seem to get it to load.
I just got it working by removing the name argument in the AMD define function. So instead of:
define('underscore.string', [], function() { ... })
Just do:
define([], function() { ... })
Then I don't even need the shim, I can just require it as a dependency in my module.
Instead of shimming you can use Burke's amd version of underscore here https://github.com/amdjs/underscore
I'm actually thinking about removing ADM declaration altogether. Underscore removed it and so I think we should too.
If you want to use AMD, you can always wrap the code by yourself. That shouldn't be very hard.
What do you think, guys? /cc @epeli @edtsech
I have the same problem as @cardinal27513, i don't know, how to make underscore.string work as either _s or _.string. I mentioned the problem here: http://stackoverflow.com/questions/16053016/underscore-string-with-requirejs
Unfortunately this is still broken
Bit late here, but... I'm all in favor of dropping AMD like Underscore.js did. Shimming is in my experience the most robust way to use third party libraries with RequireJS.
:+1 to dropping AMD. It's broken right now with RequireJS (particularly when using the optimizer).
@rwz I don't see why you need to drop AMD support. I'm having the same problem here but like @miwillhite mentioned it works fine by removing the 'underscore.string' name. Why not just remove the name and leave the line in place for those that want AMD support?