Promise.await is not a function

Hi guys!
Very weird error, which suddenly occurred after removing some npm packages and stuff:
Promise.await seems to be suddenly undefined on the server.

When I do meteor shell in cli, and enter Promise it works just fine:

> Promise
{ [Function: Promise]
  Fiber:
   { [Function: Fiber]
     yield: [Function],
     current: Fiber {},
     poolSize: 120,
     fibersCreated: 8 },
  awaitAll: [Function],
  await: [Function],
  async: [Function],
  asyncApply: [Function] }

But inside my Meteor methods, console.log(Promise) returns something completely different:

   Promise function Promise(executor){
     anInstance(this, $Promise, PROMISE, '_h');
     aFunction(executor);
     Internal.call(this);
     try {
       executor(ctx($resolve, this, 1), ctx($reject, this, 1));
     } catch(err){
       $reject.call(this, err);
     }
   }

How is this even possible?!
Also very weird:

In my Meteor method I do:

let promise = new Promise( (resolve, reject) => { ... } );
return Promise.await(promise);

and the error in server console is: :slight_smile:

[Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.]
Exception while invoking method 'placeOpenOrder' TypeError: _Promise.await is not a function

Notice the _Promise.await instead of Promise.await … is this normal?

Please help, wtf is going on?!

It looks like you may have removed the ecmascript package and/or you have replaced inbuilt Meteor Promises (which supports fibers) with a third party Promise package (which doesn’t).

  • What does your .meteor/packages file contain?
  • What does your package.json file contain?

You are very right.
I think I fixed it now, and the problem seems to have been having babel-plugin-transform-runtime as a dev dependency in my packages.json and having it active in my .babelrc.
Don’t ask why I had that in there, long story, but it seems like that this plugin replaced the Promise definition. Does this sound plausible to you?

:thumbsup: Absolutely.

1 Like

@klabauter yes that indeed applies some magic onto Promise, Set and Map and is probably the reason you’re defaulting to another Promise.

This could very well have happened because of a third party npm dependency whose peer dependency overwrites the global Promise.

To avoid similar situations, I always explicitly import it using

import { Promise } from 'meteor/promise';
3 Likes