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
Trying to use with koa #1
Comments
Basically, you have to make sure every one of your dependencies is requiring the same instance of Bluebird, and then you can just require The easiest way to do that is by making sure your application has bluebird (and co in this case) in its dependencies before you install anything else. So you'd create your package.json via running Then run Then create a file var Promise = require('bluebird');
var co = require('co');
//Optionally enable long stack traces for debugging
Promise.longStackTraces();
require('bluebird-co');
co.wrap = function(fn) {
return Promise.coroutine(fn);
}
//Optionally use bluebird Promises globally
global.Promise = Promise;
require('./app.js'); //start your application You should never have to manually edit other libraries code. However, if you have already populated your package.json with many libraries, you can achieve the desired dependency state by running |
Ah! That makes sense, got it working now. Thanks! |
It's just one of the quirks of NPM and node_modules. If you're not careful you can end up with many copies of the same library being used around your application. |
I'm actually going to reopen this issue in case anyone else has trouble integrating bluebird-co into their stack. It's a subtle problem that I can't really fix, but getting it right really pays off. |
This thread isn't as applicable now that I've switched to using Bluebird as a peer dependency and koa has/is moved/moving away from generators, so I'm going to close it. |
I put the following in node_modules/koa/lib/application.js
is this the proper approach?
The text was updated successfully, but these errors were encountered: