Load harrison:papa-parse package in Meteor - meteor

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';.

Related

Meteor Tabular errors on initialization

I'm following along the guide to setup Meteor Tabular v2.1.2 (guide). I have added the package and installed the theming packages. I'm using Meteor v2.8.0 and the project is a Blaze-based project.
In client/main.js, I set up the library as instructed.
import { $ } from 'meteor/jquery';
import dataTablesBootstrap from 'datatables.net-bs';
import 'datatables.net-bs/css/dataTables.bootstrap.css';
import "../imports/ui/body";
dataTablesBootstrap(window, $);
Now when I go to the browser, there is this error:
Can anyone help me on this?
So after serious debugging , I discovered it is enough to just import the DataTable module as such after installing it with npm
import { $ } from 'meteor/jquery';
import 'datatables.net-bs';
import 'datatables.net-bs/css/dataTables.bootstrap.css';
import "../imports/ui/body";
// You don't need the code previously here .
You can now setup you DataTable as such
$(element).DataTable(//Your config object)

Using cytoscape-qtip with meteor npm

I'm trying to get the cytoscape-qtip package working with meteor though npm.
I've installed cytoscape, jquery, qtip2 and cytoscape-qtip through with the "meteor npm install --save" command, and I'm importing and registerng them in my template as follows:
import cytoscape from 'cytoscape'
import jquery from 'jquery'
import cyqtip from 'cytoscape-qtip';
import qtip from 'qtip2';
cyqtip(cytoscape, jquery);
When I try to use the .qtip command on a cytoscape element, I get the following error:
TypeError: qtip.$domEle.qtip is not a function
I've tried usinng atmosphere packages (cytoscape:cytoscape, maxkfranz:cytoscape and maxkfranz:cytoscape-qtip) instead, but I end up getting the same error.
If I try to import the jquery bundled with meteor instead (import jquery from 'meteor/jquery'), my page will not load at all, and I get the error "TypeError: $ is not a function".
The documentation for cytoscape-qtip states
Note that jquery must point to a jQuery object with .qtip() registered if any sort of require() is used.
Could this be the problem, that qtip is somehow not registered with the jQuery object? If so, how do I register it?
I can see that this guy had a similar problem, solved by changing the import order of his scripts, but since I'm using npm I'm not sure how I can manually change the import order.
Any help would be greatly appreciated!
If there's a jQuery object on window, then qTip registers itself: https://github.com/qTip2/qTip2/blob/v3.0.2/src/core/intro.js. You may just have to set that manually for qTip to register itself.

Trouble definding NPm dependancies inside local package

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.

Local package asset with Meteor

I originally had an app using a private/settings.json asset. When attempting to make a package out of this app, I put that asset in packages/x:package/config/settings.json, and in the package.js's .onUse added
api.addFiles('config/settings.json', 'server', { isAsset: true });
I was using it successfully in the package as
settings = JSON.parse(Assets.getText('config/settings.json'));
until I removed private/settings.json. I now get
TypeError: Cannot read property 'token' of undefined
If I only keep private/settings.json, instead removing packages/x:package/config/settings.json (also changing from config/ to private/ in package.js, the package, etc) I get
error: File not found: private/settings.json
(How) can I have assets that are only local to the package? Alternatively, how can I include/use global assets in private/ in the package?
I think it makes sense that packages wouldn't be able to access assets in the app's private directory. Otherwise, a package could accidentally expose your app's private settings or assets.
It sounds like what you want is to share your settings.json file between the app and the package. There are several ways you could do this:
Put the settings into a second package and use it in your app and in your first package.
Have a method exported by your package called setSettings that allows the app to load its settings and then pass them into your package.
Use Meteor.settings, and launch your app with meteor --settings private/settings.json instead of getting the settings from an asset.

Meteor: EJSON is not defined

I'm trying to use a private JSON file to add some simple template documents to the mongo collection if it is empty:
if (Passions.find().count() === 0) {
mockPassions = JSON.parse(Assets.getText("mockups/passions.json"));
_.each(mockPassions.passions, function(passion) {
return Passions.insert(passion);
});
}
I'm getting the error:
ReferenceError: EJSON is not defined
Does anyone have any clue? I'm using Meteor 0.6.5.
Thanks
You need to bring EJSON up to the global namespace via
meteor add ejson
In meteor 0.6.5 unless you explicitly tell it to, packages are namespaced into package
Considering Latest Meteor 1.6, you can follow below steps:
A. First Approach [Independent of the meteor restart/stop/start]
Edit .meteor/packages file and add 'ejson' to end of the file
B. Second Approach
Stop Server if already running by pressing ctrl+c
Run command meteor add ejson
Restart Server using command meteor

Resources