"TypeError: Object is not async iterable" with async generator function

Viewed 3006

I'm trying to implement an async generator function within my meteor application. But I am unable to get it working because of the following error:

W20190614-11:14:39.757(2)? (STDERR) (node:16217) UnhandledPromiseRejectionWarning: TypeError: Object is not async iterable
W20190614-11:14:39.757(2)? (STDERR)     at _asyncIterator (/Users/sst/entw/resy/resyStat/node_modules/@babel/runtime/helpers/asyncIterator.js:16:9)
W20190614-11:14:39.757(2)? (STDERR)     at Promise.asyncApply (server/main.js:33:3)
W20190614-11:14:39.757(2)? (STDERR)     at /Users/sst/.meteor/packages/promise/.0.11.2.pg5aj7.wk7c++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:40
W20190614-11:14:39.757(2)? (STDERR) (node:16217) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
W20190614-11:14:39.757(2)? (STDERR) (node:16217) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Here is the code I wrote to reproduce the error:

// server/main.js

async function* counter(max) {
  let count = 0;
  while (count <= max) {
    yield await Promise.resolve(count++);
  }
}

(async () => {
  for await (const num of counter(3)) {
    console.log(num);
  }
})();

My project setup:

// Meteor: v1.8.1

// package.json
{
  "dependencies": {
    "@babel/runtime": "^7.4.5",
    ...
  },
  "devDependencies": {
    "@babel/plugin-transform-runtime": "^7.4.4",
    "babel-plugin-transform-decorators-legacy": "^1.3.5",
    ...
  },
  ...
}

// .babelrc
{
  "presets": ["env"],
  "plugins": ["decorators-legacy", "@babel/plugin-transform-runtime"]
}

This is what I already debugged:

const it = counter(3);
console.log(it); // { _invoke: [Function send] }

console.log(it[Symbol.iterator]);      // undefined
console.log(it[Symbol.asyncIterator]); // undefined

I previously didn't have @babel/plugin-transform-runtime install but it was suggested to use it with @babel/runtime on their docs so I installed it. Didn't help much tho :/

EDIT:
Maybe I should clarify: I think this error is somewhat babel related because when I try to get the function it[Symbol.asyncIterator] - it doesn't exist. Normally, this function produces the iterator object but it isn't there.

0 Answers
Related