Why Meteor don't automatically install npm modules?


Just cloned a meteor app source code and launch meteor run

Meteor automatically installed needed meteor packages, but gave me “errors” like :

Unable to resolve some modules:

“underscore” in /xxx/yyy/imports/admin/file.js (web.browser)

If you notice problems related to these missing modules, consider running:

meteor npm install --save underscore

After installing all of them, manually, all works great (as usual with meteor :wink: )

Questions :
Am I doing something wrong ? Why Meteor don’t automatically install npm modules ?

Thanks for your help

You probably need to import it as

import { _ } from "meteor/underscore";

…as opposed to

import _ from "underscore";
1 Like

Other than that, i.e. if you want to use any particular npm module, you just need to install it as indicated with meteor npm install --save <packagename>, or, if you have installed npm, simply with npm install --save <packagename>

Meteor simply won’t do this for you automatically.

First off, please don’t install any of the wrapper packages from atmosphere. Those are outdated relics from a time before NPM support.

As for auto installs of NPM packages, there is a PR which will support this and it should be merged in the near future.


Thx @peterfkruger.

What’s differences between those two syntax ? :thinking: Is the first one a “kind of” atmospheres package ?

Great news @copleykj :pray::blush:

It seems “obvious” for me that this kind of things should be done automatically by meteor … Maybe some technical things make this difficult.

Bref, thanks :blush:

1 Like

Those are two different packages. Meteor comes with an embedded (and modified) underscore package, see Documentation of Meteor’s underscore package. It is probably quite outdated, but you can still use it if you want, and then you don’t need to add it as an npm package. In this case it needs to be imported the way I indicated:

import { _ } from "meteor/underscore";

That’s the way how Atmosphere packages need to be imported, see the Meteor documentation Using Atmosphere Packages.

The other way to use this particular package is to add it via npm. Then you would import it with

import _ from "underscore";

Note however that most people tend to use lodash instead of underscore (myself included).
See Lodash vs Underscore: Dash of the titans (2017)

1 Like

Thx @peterfkruger.

For now, it’s a project that I cloned from GitHub, so I’ll check that.

There are a lot of packages in Meteor’s package system (Atmosphere) which use npm packages internally. In many of them, such as jquery, etc, there might be an embedded version, or it might require you to install an npm module yourself. The reason is that lets you pick and choose the version you would like for your own project, rather than locking you to whatever version is embedded in the Atmosphere/Meteor package. Meteor is old enough that it predates the standardization of npm as the package manager for node.js - but well maintained enough, that it has embraced npm completely.

In general, npm packages should be preferred over Atmosphere packages, if one exists. The one exception for me is packages that leverage the additional integration features Atmosphere provides with Meteor. Many of the packages I maintain are Atmosphere packages for this reason - they might provide separate server and client bundles, for example, which is more tricky to set up with an npm package. Sometimes an Atmosphere package might simply extend the functionality of an npm package. For example, I made a “loadable” package (npdev:svelte-loadable) on top of the npm package svelte-loadable. My Atmosphere package is the last mile of integration with Meteor, providing the glue needed to get SSR working, and some other Meteor specific things - but it still leverages the npm package internally (and actually, I contributed quite a number of features to the upstream package to make it all work).

So that’s the long answer, the short answer is, try running the command given: meteor npm install --save underscore that should get you up and running.

1 Like