Can I Update Meteor Underscore package? - meteor

Meteor uses a very dated 1.5.2 version of Underscore. Two years old this Sept and missing a lot of great stuff that is in the current 1.8.2 library.
Can the package be updated?

You can update the version used in your app, though not the version used by Meteor itself. See this GitHub issue.
The easiest solution is to just replace Underscore with Lodash, which has even more features than the latest Underscore. Per this thread, it’s this easy:
meteor add alethes:lodash
And in your startup code:
// Use lodash instead of underscore
_ = lodash;
If you prefer the latest Underscore instead of Lodash, it looks like at the moment you’ll need to download the file from underscorejs.org and save it into either your lib or client/compatibility folder. It should execute after Meteor’s libraries themselves load, and hijack the _ variable. You can also initialize it with _.noConflict(), in which case you can let _ stay with Meteor’s version and you can assign the new Underscore to something else, e.g. underscore = _.noConflict();.
I should probably mention that either of these solutions will leave you with both libraries (Meteor’s old version of Underscore, and the new library you’re using instead) downloading to the client. Until Meteor itself upgrades (see GitHub issue above), that is unavoidable.

My solution using lodash with Meteor ES2015:
meteor npm i lodash --save
and import lodash /imports/startup/client/index.js:
import lodash from 'lodash';
window._ = lodash;
Regards, Nicholls

Related

Do I need two versions of jQuery in Meteor?

In my Meteor project it looks like I've got two versions of jQuery running. My app is using the atmosphere package materialize:materialize and I know that one of its dependencies is jQuery. In my meteor/packages folder it shows version 1.11.10 being used.
But the confusing part is in my External Libraries folder. It also shows a version of jQuery 2.0.0. The only npm package that I have used for my app was when I brought in the babel runtime that was required for Meteor version 1.4.3.2. I had in the past installed Materialize from npm but removed it some time ago. Confused to why that jQuery 2 is there.
This is fine, it happens this way because of package dependencies, Meteor depends on what is quite an old version of JQuery, and one of your npm packages depends on 2.0.
It does seem strange, but it isn't a problem.
What is happening here is some of the meteor packages depends on jquery and some of the npm packages does the same so you end up having the lib installed twice. Nothing terrible except that clients would have to download the same library twice. This is a known bug here https://github.com/meteor/meteor/issues/6626. Not sure where is it going though, it's been there for quite long already.

Meteor App hangs when adding Ecmascript

I recently updated my Meteor App to 1.3 and also want to migrate to the "new style" of coding, meaning ES2015, React, later on Apollo/GraphQL.
First I only want to use the import syntax. But when I meteor add Ecmascript it will then hang on meteor:
Building for web.browser /
takes forever.
Any ideas why?
I had the same issue. In my case this is how I got it fixed. May be it is the same for you.
I had multiple third party libraries in client/lib folder.
To use ES6 syntax, I added 'ecmascript' to my .meteor/packages file and after that issuing the meteor command would just hang.
During trial and error, I figured out that
deleting the client/lib directory made meteor to start
.
For the libraries my application depends on, I went to https://atmospherejs.com, searched for the meteor specific package name for the dependency and added these to .meteor/packages file.
e.g: Instead of copying the datatables.js and datatables.css inside client/lib folder, add 'menway:jquery-datatables' to .meteor/packages or issue the command meteor add menway:jquery-datatables

how to request angular version that is lower than default with angular-meteor

I'm trying to use a third party commercial JS library in my angular-meteor project
The vendor just informed me, that they only support angular version 1.3.11
Is there a way to install urigu:angular-meteor with this specific version of angular?
According to the meteor documentation you can set a version using #= so it should be like that:
meteor add angularjs:angular#=1.3.11
However, doing so you might have versions conflict like that:
>meteor add angularjs:angular#=1.3.11
=> Errors while adding packages:
While selecting package versions:
error: Potentially incompatible change required to top-level dependency: urigo:angular 0.6.8, was 0.8.4.
Constraints on package "urigo:angular":
To allow potentially incompatible changes to top-level dependencies, you must pass --allow-incompatible-update on the command line.
So you have here few alternatives:
Downgrade urigo:angular: I think this is not a good option, there might be major changes since the package is pretty new.
Convince the vendor to "take the risk"
Since angular is much more mature that angular-meteor and 1.3.11 to 1.3.15 should not have breaking changes, this option have a clear advantage.
If you do wish to use the first option, add --allow-incompatible-update to the command line.

Meteor package file inclusion

I want to build a meteor package to wrap an existing javascript library. I would like to include the library as a git submodule. I only need 2 files from the submodule. If I only include these two in package.js will the rest of the files be ignored by meteor and not built into the package?
The only files that will end up in your package are those that will be explicitly added with api.addFiles routine (look here).
BTW, If you're planning to wrap an existing JavaScript library then you should probably start by getting familiar with autopublish project. For more details watch this video.

How do you use the mrt:natural package in an app?

I have installed http://atmospherejs.com/mrt/natural by 'meteor add mrt:natural' (I am using Meteor 0.9.1). It seems to be installed ok, but the 'usage' says to simply call :
natural = Natural
This doesn't work when applied on the server or client side. I'm sure this must be so obvious as I can't see anyone else having the problem...
Yes, I am pretty new to Meteor.
This package doesn't seem to be maintained (last update 6 Jun 2013). There's also no need for it to be, since it's a simple wrapper for a Npm package, which can be now loaded in a better way.
Add npm package to your app with
meteor add meteorhacks:npm
and then create packages.json file with natural specified as per documentation. Then you'll be able to require natural with Meteor.npmRequire('natural');.

Resources