How to derive required steps for importing


#1

I am using Angular-Meteor and am still at a bit of a loss with regard to the question of how to use external packages in my apps.

All is fine when there are complete instructions, of course.

But oftentimes, instructions do not go much further than

meteor add something

or

npm install something --save

I then usually find myself at a loss on how to properly include the package in my app.

  1. How to form the import statement (import <path> vs. import X from Y as
  2. How do I know how to form an import statement? (Which strings for X and Y to use in import X from 'Y';

One example is angular-meteor-auth.

Is there some documentation that allows understanding the different kinds of importing functionality into an Angular-Meteor app or a set of rules/checklist on how to determine from source how to form import statements for any given pakckage.

Can anyone advise?


How to display notifications with Angular?
#2

As I wrote in the other thread, you need to do it the Meteoric way; when you npm install directly, that’s just your local npm and not the scope of your meteor project.


#3

Hi @areich, thanks for the pointer. That explains my item 1. and certainly put me on the right track for my issue with ngToast in the other thread.

As far as importing the package after correct install, and using the example of ngToast, I was reading the docs you referenced as saying that I should use

import ng-toast from 'ng-toast'; // package name is 'ng-toast'

which didn’t work.

Trying

import ngToast from 'ng-toast';

was more successful.

I then got an error telling my that ngSanitize was missing. Again, I had to make an educated guees and got the error removed with

import ngSanitize from 'angular-sanitize';

In the above cases, how should I have come to know that that ngToast and ngSanitize are the precise string required in the import statement?


#4

Does this help?

Regarding your last question, you can use any valid identifier. So you could actually import AnyValidIdentifier from 'something', but not e.g. import x-y because that’s actually identifier x - (substract) identifier y. Just think valid variable names.

You also don’t always need a name if you just need to import something without ever using it, e.g. import from 'something' is fine too.

Generally if some packages need another package, they handle this themselves, except in the case of peer dependencies, which are expected to be installed app-wide.


#5

That does clear things up a bit more indeed. Thanks!