How to import 'Npm' in meteor 1.3?

I’ve been playing around with Meteor 1.3 and found the experience of being able to import npm modules as well as meteor packages to be very delightful.

I’m trying to use fibers/future on the server, and found lots of examples of Npm.require('fibers/future') Where does Npm come from, and how do I import it (or how do I import the fibers/future module)?

Thanks :slightly_smiling:

1 Like

After installing fibers just do:
import Fibers from 'fibers'

Then you are good to go…

3 Likes

Regarding Fibers & Futures:

For some reason, cannot import Future from ‘fibers/future’

> import Future from 'fibers/future'
> Future
ReferenceError: Future is not defined

Closer was:

> import * as Future from 'fibers/future'
> Future
{ task: [Function],
  wrap: [Function],
  wait: [Function: wait],
  fromPromise: [Function],
  default:
   { [Function: Future]
     task: [Function],
     wrap: [Function],
     wait: [Function: wait],
     fromPromise: [Function] } }

Still, that produces an object, not a function. Need to use Future.default to get the function.

Or, using CommonJS require works:

> const Future = require('fibers/future')
> Future
{ [Function: Future]
  task: [Function],
  wrap: [Function],
  wait: [Function: wait],
  fromPromise: [Function] }

I’d love to know why this is.

@mhurwi, check out [1.3.1] Strange import behavior. In particular (from benjamn):

Unfortunately, the semantics of import are not really compatible with meteor shell or any shell-like REPL environment: https://github.com/meteor/meteor/issues/6271#issuecomment-187999135

Because symbols imported using import are mutable bindings, a compiler for import statements needs the complete picture: not only what you imported and what module it came from, but where those symbols are used in the rest of your code. A REPL divorces the import statement from the symbol usage, making the compiler’s job impossible.

In short, when you’re using meteor shell, you need to use require.

Thanks! That clears it up.

1 Like

Ok. But this is same on server.
I have import Future from 'fibers/future'; on server file and it gives me:

Unable to resolve some modules:

  "fibers/future" in .../server/methods/uploads.js (os.linux.x86_64)
                                              
If you notice problems related to these missing modules, consider running:
                                              
  meteor npm install --save fibers