New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dependency on 'window' breaks in nodejs #4
Comments
Can you test by modifying the lib to look like this: (function(window) {
/* Keep source code the same */
})(typeof window == "undefined" ? global : window);
or
})(this); And let me know if that works or fails. |
Hey there :). So wrapping the use plugin as above does indeed remove the "window is not defined" traceback, so the tests actually run, but it's not being defined... that is: define(['use!expect'], function(expect){
var assert = require('assert');
suite("Using the 'use' plugin in node", function(){
test("it should be defined", function() {
assert(expect !== undefined);
});
});
}); fails. So I guess it'll require a bit more thought for nodejs support. If you've got an idea and enough time to dump it here, I can have a go. I'd already tried adding: var attach_to;
if (window !== undefined){
attach_to = window
} else {
attach_to = root;
} and doing s/window/attach_to in use.js, but it had the same effect as your solution (the test would run, but 'expect' wasn't defined). Thanks either way. |
Hey I needed to get use.js working in node, if your still having issues might be worth checking out iaincarsberg@fcfe816 I've only tested it with underscore and flow-js, so the "|| exports[]" change may need expanding depending on how other libraries work. Once I've had time to test it with more libraries I'll submit a pull request. |
I got the same issue while using the "use!" plugin with require.js on node. The setup is relatively complex, the plugin being configured for backbone, underscore and jqueryUI. The first tests of the modification proposed by @iaincarsberg is really promising. |
I've tested a little more in depth the modification, and wasn't able to load jqueryUI library. The error reported is this:
the configuration used in require.js
I will try to dig into this issue this week, will see if I find something. |
@idflood jquery is a named lib |
@tbranyen : Thanks, I was just working on this, and found that manually loading jquery before jquery-ui helped a lot. I came to this solution after seeing that jQuery is attached to the window object:
Here is the file where all the black magic happens: https://github.com/idflood/ThreeNodes.js/blob/mocha/src/scripts/testrunner.coffee But I'm starting to add a more and more inelegant code in the testrunner (and classes in src/scripts/threenodes but that is a little off topic). I will try your suggestion : ) |
This issue is also affecting me. I had to undo incorporating use.js and go back to re-wrapping my non-AMD third party libs for now because I'm using them in the browser and node. |
Fixed in the latest build. |
Hey there :) I think you're already aware of this by the comment in the code:
// Use window for now (maybe this?)
but I just tried a few ways to get the use plugin working with node, but didn't manage.
< ReferenceError: window is not defined
< at /home/michael/dev/ogt/backbone-test/app/scripts/libs/requirejs/plugins/use.js:52:21
< at Function.execCb (/home/michael/dev/ogt/backbone-test/node_modules/requirejs/bin/r.js:1872:25)
< at execManager (/home/michael/dev/ogt/backbone-test/node_modules/requirejs/bin/r.js:541:31)
< at /home/michael/dev/ogt/backbone-test/node_modules/requirejs/bin/r.js:642:25
< at execManager (/home/michael/dev/ogt/backbone-test/node_modules/requirejs/bin/r.js:619:17)
< at main (/home/michael/dev/ogt/backbone-test/node_modules/requirejs/bin/r.js:944:17)
< at callDefMain (/home/michael/dev/ogt/backbone-test/node_modules/requirejs/bin/r.js:955:18)
< at Object.completeLoad (/home/michael/dev/ogt/backbone-test/node_modules/requirejs/bin/r.js:1534:21)
< at Function.load (/home/michael/dev/ogt/backbone-test/node_modules/requirejs/bin/r.js:2286:17)
< at /home/michael/dev/ogt/backbone-test/node_modules/requirejs/bin/r.js:1281:37
The text was updated successfully, but these errors were encountered: