I am trying to create a package, but I cannot require npm modules inside the package. This results in a
Cannot find module '..path../crypto'
/packages/s3policy/lib/s3policy.js
crypto = Npm.require('crypto');
S3Policy = {};
S3Policy.readPolicy...
/packages/s3policy/package.js
Npm.depends({
'crypto': '0.0.3'
});
Package.describe({
name: 's3policy',
summary: 'S3 policy API',
version: '0.0.1'
});
Package.on_use(function (api) {
api.add_files('lib/s3policy.js', ['server']);
api.export('S3Policy');
});
Any idea as to why I am unable to require the crypto module?
Maybe this helps?
crypto is a built in node package (http://nodejs.org/api/crypto.html). It doesn't need to be installed. However, the npm crypto package is 2 year old unmaintained code that is often downloaded by mistake (https://www.npmjs.org/package/crypto). Either Meteor or NPM gets confused because the packages have the same name, but it doesn't really matter because you don't want the NPM package.
Just take crypto out of your npm packages and you should be fine.
Related
I downloaded the harrison:papa-parse package : meteor add harrison:papa-parse.
But now i need to load it in my Meteor application so i can use it.
I imported the package in my Component :
import { Papa } from 'meteor/harrison:papa-parse';
and then i need to declare the module in typing.d.ts file
declare module 'meteor/harrison:papa-parse' {
// something here like export const Papa; ?
}
, but after that i'm lost ! and i have an error: cannot read property 'parse' of undefined
In My component :
Papa.parse("http://mywebsite/test.csv", {
download: true,
complete: function(results) {
console.log(results);
}
});
Maybe there's an easy way to import the package easly and i'm trying to complicate it ?
The meteor package exports the "Papa" variable on the server, which means you have to call it from a server process.
Delete this line from your code, because it won't do anything:
import { Papa } from 'meteor/harrison:papa-parse';
Meteor packages don't need to be imported, part of the package spec is an automatic import of whatever variables are needed.
According to the documentation this package should be available in the browser, but for some reason the meteor package author made the decision to only expose it in the server.
There is also an npm package available, which might be a better path for you to follow.
You don't need the harrison:papa-parse meteor package. You can install and use the papaparse NPM package directly. In the root of your meteor project run meteor npm install --save papaparse. Then, in your client script you can import with import Papa from 'papaparse';.
In node, it's easy to do
"dependencies": {
"express": "^4.13.3",
"node-uuid": "^1.4.3",
"PACKAGE_NAME": "git://github.com/USERNAME/REPO_NAME.git#COMMIT_SHA"
}
In meteor I can include an npm module using var uuid = Meteor.npmRequire('node-uuid'); for npm packages that are published, but when pointing my package at github (the same way I would in a node project) I get an error.
How does one doe this with Meteor? When trying to do the same thing in the package.json I get the following error
"must declare exact version of dependency:"
Any help on how to include a package that's not published to Npm?
You need to specify the commit and point to the archive. From https://atmospherejs.com/meteorhacks/npm:
If you need to install an npm module from a specific commit, use the
syntax:
{ "googleapis": "https://github.com/bradvogel/google-api-nodejs-client/archive/d945dabf416d58177b0c14da64e0d6038f0cc47b.tar.gz" }
I want to include mobile verification for the users in my app.Tried adding the accounts-phone package ::*$ meteor add okland:accounts-phone *
but error was shown while including that package.
[Edit:1]
*=> Errors while adding packages:
While selecting package versions:
error: Conflict: Constraint npm-bcrypt#=0.7.7 is not satisfied by npm-bcrypt
0.7.8_2.
Constraints on package "npm-bcrypt":
* npm-bcrypt#=0.7.8_2 <- accounts-password 1.1.1
* npm-bcrypt#=0.7.7 <- okland:accounts-phone 0.0.10*
This is a problem with the older versions of bycrpt and the old accounts-base package it depends on. I recently made a pull request to the okland:accounts-phone package which updates accounts-phone to depend on accounts-password and a newer bycrpt version.
Alternatively, if you don't want to wait, you can download his repo locally (okland:accounts-phone) into a packages dir at the root level of your project, and change the packages.js file as such:
Package.describe({
name : 'accounts-phone',
--skipped some lines--
Package.onUse(function (api) {
-api.use('npm-bcrypt#=0.7.8_2', 'server');
+api.use('npm-bcrypt#=0.8.7_1', 'server');
-api.use('accounts-base#1.0.2', ['client', 'server']);
+api.use('accounts-password#1.2.14', ['client', 'server']);
// Export Accounts (etc) to packages using this one.
-api.imply('accounts-base#1.0.2', ['client', 'server']);
+api.imply('accounts-password#1.2.14', ['client', 'server']);
(Make sure to get rid of the '+' and '-', they're just there to indicate what's deleted and what's new). Then, add the local using meteor add accounts-phone'. It will work just fine.
What are the constraints that Meteor is trying to resolve when it loads the packages at startup? Is it all related to versioning or is it actually looking at the code that you load with ap.use() in packages.js?
I am getting this error when I try to start up my project. I have a super-simple package file that I created with the meter create --package command. I put all of my files that make up the package into the directory that it created and moved that directory to .meteor/packages. I'm just trying to create a local package for now. Here's the contents of package.js in that directory:
Package.describe({
name: 'ammap-meteor',
summary: 'mapping library packaged for meteor ',
version: '1.0.0',
});
Package.onUse(function(api) {
api.versionsFrom('METEOR#0.9.0');
api.addFiles('ammap.js');
api.addFiles('ammap_amcharts_extension.js');
});
Package.onTest(function(api) {
api.use('tinytest');
api.use('ammap-meteor');
api.addFiles('ammap-meteor-tests.js');
});
My ammap-meteor-tests.js file is blank for the moment but it exists. Would that make a difference? And I assume you just omit the git: property from Package.onUse() for a local package, is that right?
OK, I was able to get past that error with the publish command:
meteor publish --create
So I did not succeed in making a local package (still not clear on that) but at least I can get the package to load now.
I'm trying to install the Spooky module in meteor (this one is in my public folder: app/public/node_modules).
I've read answers in this post and added the following code in server/server.js
Meteor.startup ->
path = Npm.require 'path'
fs = Npm.require 'fs'
base = path.resolve '.'
isBundle = fs.existsSync base + '/bundle'
modulePath = base + (if isBundle then '/bundle/static' else '/public') + '/node_modules'
spooky = Npm.require modulePath + '/spooky'
But when I'm running meteor I get:
Error: Cannot find module '/Users/mac/Documents/websites/app/.meteor/local/build/programs/server/public/node_modules/spooky'
You need to create a smart package to use Npm modules in your app. Alternatively you can use meteor-npm.
You can't use Npm.require on its own for non standard npm modules like spooky.
If you use meteor-npm you can install it with meteorite: mrt add npm
Then use Meteor.require("spooky") instead, after you have added the module to your packages.json. You can have a look here for more details: http://meteorhacks.com/complete-npm-integration-for-meteor.html.
The official way to do it is to make your own smart package to wrap the npm module in. There is an example of such a package: https://github.com/avital/meteor-xml2js-npm-demo
The example uses xml2js as the npm module, but you could swap the names around so its spooky instead.
Then you can add this package into your /packages folder (say with the name spooky), and add it to your meteor project with meteor add spooky.
The packages on atmosphere.meteor.com have more examples of this, they pretty much do the same thing (e.g stripe (https://atmosphere.meteor.com/package/stripe)).
The article Akshat linked to has been updated:
cd project
meteor add meteorhacks:npm
Edit project/packages.json:
{
"redis": "0.8.2",
"github": "0.1.8"
}
Use those npm modules:
var Github = Meteor.npmRequire('github');
var github = new Github();
github.gists.getFromUser({user: 'arunoda'}, function(err, gists) {
console.log(gists);
});