Use npm in Meteor packages
was trying to figure out how to download an npm package in Meteor. Specifically, I tried usingfuture-npm
I tried to do this:
Package.describe({
summary: "Blah blah",
version: '0.0.1'
});
Npm.depends({future: "2.3.1"});
Package.onUse(function (api) {
api.addFiles('lubert.js', 'server');
api.export('Lubert');
});
Unfortunately I got the following console error
Uncaught ReferenceError: Npm is not defined
I read the documentation and there is no download of any dependency
What am I doing wrong?
Update 2: My package.js looks like
Package.describe({
name: 'trepafi:package',
summary: '',
version: '0.0.3',
git: 'https://github.com/trepafi/meteor-package.git'
});
Npm.depends({
"future": "2.3.1"
});
Package.onUse(function(api) {
api.versionsFrom('1.0');
api.use(['tracker', 'underscore'], ['client']);
api.addFiles(['package.js'], ['client']);
api.export('Package', ['client']);
});
Update 1: My package.json looks like
{
"name": "trepafi-package",
"version": "0.0.3",
"description": "Package for Meteor",
"repository": {
"type": "git",
"url": "https://github.com/trepafi/meteor-package.git"
},
"author": "Lubert Palacios",
"license": "MIT",
"homepage": "https://github.com/trepafi/meteor-package",
"dependencies": {
"future": "^2.3.1"
}
}
I've also tried with meteorhacks: npm without success. It would be nice if I could use the "native" way
source to share
You have to group everything Npm.require
at the end of your file package.js
.
For future-npm
. You don't need Npm.depends
to package.js
, stupid. It's already included in the meteor .. just Npm.require
somewhere and you're good to go. For this:
-
Don't be ambiguous with the name
package.js
. Use insteadtrepafi:package.js
. -
You don't need
package.json
..Npm.depends
you have. -
Remove this:
api.addFiles(['package.js'], ['client']);
as it looks like a circular dependency. Yo dawg i herd you liek package.js in you package.js .. not cool Xzibit. -
And since Npm.require only works server side, you need to enable it
trepafi:package.js
as server side. eg:api.addFiles(['trepafi:package.js'], ['server']);
So your structure should be at least:
trepafi:package/
- package.js
- trepafi:package.js
- <other files..>
You don't need package.json for Future
.. it's already included in Meteor.
Yours package.js
should look like this:
Package.describe({
name: 'trepafi:package',
summary: '',
version: '0.0.3',
git: 'https://github.com/trepafi/meteor-package.git'
});
Package.onUse(function(api) {
api.versionsFrom('METEOR@1.0');
api.use(['tracker', 'underscore','meteor'], ['client']);
api.addFiles(['trepafi:package.js'], ['server']);
api.export('Package', ['client']);
});
//if you really need Npm.depends:
Npm.depends({
'prerender-node': '1.0.6',
'send' : '0.10.1'
});
// we don't need no package.json
Yours trepafi:package.js
should look like this:
var Future = Npm.require('future');
var future = new Future();
// use your future to make Doc Brown proud.
var useFuture = function(asyncFunc) { //expects function with callback somewhere
asyncFunc(function(err, result) {
if(err) future.throw("OMG something went wrong!");
else return future.return(result);
});
return future.wait();
};
Meteor.startup(function() {
//something
});
READ:
Notable changes in package.js
: versionsFrom
and are api.use
now added meteor
.
Good luck!
source to share