{"action":"created","issue":{"url":"https://api.github.com/repos/babel/babel/issues/4487","repository_url":"https://api.github.com/repos/babel/babel","labels_url":"https://api.github.com/repos/babel/babel/issues/4487/labels{/name}","comments_url":"https://api.github.com/repos/babel/babel/issues/4487/comments","events_url":"https://api.github.com/repos/babel/babel/issues/4487/events","html_url":"https://github.com/babel/babel/issues/4487","id":175944164,"number":4487,"title":"require babel-polyfill and babel-core statements are preceded by asycn runtime code. plugin[babel-plugin-transform-async-to-generator]","user":{"login":"devarsh","id":644099,"avatar_url":"https://avatars.githubusercontent.com/u/644099?v=3","gravatar_id":"","url":"https://api.github.com/users/devarsh","html_url":"https://github.com/devarsh","followers_url":"https://api.github.com/users/devarsh/followers","following_url":"https://api.github.com/users/devarsh/following{/other_user}","gists_url":"https://api.github.com/users/devarsh/gists{/gist_id}","starred_url":"https://api.github.com/users/devarsh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devarsh/subscriptions","organizations_url":"https://api.github.com/users/devarsh/orgs","repos_url":"https://api.github.com/users/devarsh/repos","events_url":"https://api.github.com/users/devarsh/events{/privacy}","received_events_url":"https://api.github.com/users/devarsh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-09T07:20:31Z","updated_at":"2016-09-09T07:42:56Z","closed_at":null,"body":"<!---\r\nBEFORE YOU SUBMIT please read the following:\r\n\r\nIf you have a support request or question please submit them to one of this resources:\r\n\r\n* Discussion Forum: https://discuss.babeljs.io/\r\n* StackOverflow: http://stackoverflow.com/questions/tagged/babeljs using the tag `babeljs`\r\n* Slack community: https://slack.babeljs.io/\r\n* Also have a look at the Readme for more information on how to get support:\r\n  https://github.com/babel/babel/blob/master/README.md\r\n\r\nIssues on github are only related to problems of babel itself and we cannot answer \r\nsupport questions here.\r\n-->\r\n\r\n<!--- Provide a general summary of the issue in the title above -->\r\n\r\n### Input Code\r\n<!--- If you're describing a bug, please let us know which sample code reproduces your problem -->\r\n\r\n```js\r\nrequire(\"babel-core/register\")\r\nrequire(\"babel-polyfill\")\r\n\r\nvar fetch = require('isomorphic-fetch')\r\n\r\nfunction fetchReddit(topic) {\r\n  const redditUrl= `https://www.reddit.com/r/${topic}.json`\r\n  return new Promise((resolve,reject) => {\r\n    fetch(redditUrl).then(response => response.json()).then(result => resolve(result.data.children))\r\n  })\r\n}\r\n\r\nasync function read(topic) {\r\n  var json = await fetchReddit(topic)\r\n  console.log(json)\r\n}\r\n\r\nread('home')\r\n```\r\n\r\n### Babel Configuration (.bablerc, package.json, cli command)\r\n<!--- If describing a bug, tell us what your babel configuration looks like -->\r\n.babelrc\r\n```js\r\n{\r\n  \"presets\": [\"es2015\", \"es2016\", \"es2017\", \"stage-2\"],\r\n}\r\n```\r\npackage.json\r\n```console\r\ndevDependencies\": {\r\n   \"babel\": \"^6.5.2\",\r\n    \"babel-cli\": \"^6.11.4\",\r\n    \"babel-core\": \"^6.10.4\",\r\n    \"babel-eslint\": \"^6.1.0\",\r\n    \"babel-plugin-transform-async-to-generator\": \"^6.8.0\",\r\n    \"babel-preset-es2015\": \"^6.9.0\",\r\n    \"babel-preset-es2016\": \"^6.11.3\",\r\n    \"babel-preset-es2017\": \"^6.14.0\",\r\n    \"babel-preset-stage-0\": \"^6.5.0\",\r\n    \"babel-register\": \"^6.11.6\",\r\n    \"isomorphic-fetch\": \"^2.2.1\",\r\n}\r\n```\r\n\r\n### Current Behavior\r\nThe `read` function preceeds the require statement, which will result in undefined `regeneratorRuntime`\r\n```js\r\n\"use strict\";\r\n\r\nvar read = function () {\r\n  var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(topic) {\r\n    var json;\r\n    return regeneratorRuntime.wrap(function _callee$(_context) {\r\n      while (1) {\r\n        switch (_context.prev = _context.next) {\r\n          case 0:\r\n            _context.next = 2;\r\n            return fetchReddit(topic);\r\n\r\n          case 2:\r\n            json = _context.sent;\r\n\r\n            console.log(json);\r\n\r\n          case 4:\r\n          case \"end\":\r\n            return _context.stop();\r\n        }\r\n      }\r\n    }, _callee, this);\r\n  }));\r\n\r\n  return function read(_x) {\r\n    return _ref.apply(this, arguments);\r\n  };\r\n}();\r\n\r\nfunction _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { return step(\"next\", value); }, function (err) { return step(\"throw\", err); }); } } return step(\"next\"); }); }; }\r\n\r\nrequire(\"babel-core/register\");\r\nrequire(\"babel-polyfill\");\r\n\r\nvar fetch = require('isomorphic-fetch');\r\n\r\nfunction fetchReddit(topic) {\r\n  var redditUrl = \"https://www.reddit.com/r/\" + topic + \".json\";\r\n  return new Promise(function (resolve, reject) {\r\n    fetch(redditUrl).then(function (response) {\r\n      return response.json();\r\n    }).then(function (result) {\r\n      return resolve(result.data.children);\r\n    });\r\n  });\r\n}\r\n\r\nread('home');\r\n```\r\n\r\n### Expected Behavior\r\n```js\r\n\"use strict\";\r\n\r\n\r\nrequire(\"babel-core/register\");\r\nrequire(\"babel-polyfill\");\r\n/* everthing else after the require statement */\r\nvar read = function () {\r\n  var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(topic) {\r\n    var json;\r\n    return regeneratorRuntime.wrap(function _callee$(_context) {\r\n      while (1) {\r\n        switch (_context.prev = _context.next) {\r\n          case 0:\r\n            _context.next = 2;\r\n            return fetchReddit(topic);\r\n\r\n          case 2:\r\n            json = _context.sent;\r\n\r\n            console.log(json);\r\n\r\n          case 4:\r\n          case \"end\":\r\n            return _context.stop();\r\n        }\r\n      }\r\n    }, _callee, this);\r\n  }));\r\n\r\n  return function read(_x) {\r\n    return _ref.apply(this, arguments);\r\n  };\r\n}();\r\n\r\nfunction _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { return step(\"next\", value); }, function (err) { return step(\"throw\", err); }); } } return step(\"next\"); }); }; }\r\n\r\nvar fetch = require('isomorphic-fetch');\r\n\r\nfunction fetchReddit(topic) {\r\n  var redditUrl = \"https://www.reddit.com/r/\" + topic + \".json\";\r\n  return new Promise(function (resolve, reject) {\r\n    fetch(redditUrl).then(function (response) {\r\n      return response.json();\r\n    }).then(function (result) {\r\n      return resolve(result.data.children);\r\n    });\r\n  });\r\n}\r\n\r\nread('home');\r\n```\r\n\r\n| software         | version\r\n| ---------------- | -------\r\n| Babel            |  6.5.2\r\n| node             | 4.3.0\r\n| npm              | 3.7.2\r\n| Operating System | OS X EL Capitan\r\n"},"comment":{"url":"https://api.github.com/repos/babel/babel/issues/comments/245842828","html_url":"https://github.com/babel/babel/issues/4487#issuecomment-245842828","issue_url":"https://api.github.com/repos/babel/babel/issues/4487","id":245842828,"user":{"login":"loganfsmyth","id":132260,"avatar_url":"https://avatars.githubusercontent.com/u/132260?v=3","gravatar_id":"","url":"https://api.github.com/users/loganfsmyth","html_url":"https://github.com/loganfsmyth","followers_url":"https://api.github.com/users/loganfsmyth/followers","following_url":"https://api.github.com/users/loganfsmyth/following{/other_user}","gists_url":"https://api.github.com/users/loganfsmyth/gists{/gist_id}","starred_url":"https://api.github.com/users/loganfsmyth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loganfsmyth/subscriptions","organizations_url":"https://api.github.com/users/loganfsmyth/orgs","repos_url":"https://api.github.com/users/loganfsmyth/repos","events_url":"https://api.github.com/users/loganfsmyth/events{/privacy}","received_events_url":"https://api.github.com/users/loganfsmyth/received_events","type":"User","site_admin":false},"created_at":"2016-09-09T07:42:56Z","updated_at":"2016-09-09T07:42:56Z","body":"The issue here is that you're using a function declaration, which because of hoisting _is_ technically supposed to be at the top of the file. Babel doesn't know anything about `require` statements, so it has no way of knowing it is moving that logic above the code that it depends on.\r\n\r\nTwo options\r\n\r\n1. Make a separate entry point, e.g.\r\n\r\n    ```\r\n    require(\"babel-core/register\")\r\n    require(\"babel-polyfill\")\r\n\r\n    require('./app') // load the app explicitly after the polyfill\r\n    ```\r\n\r\n2. Pass them when you start node, e.g.\r\n\r\n    node -r babel-polyfill -r babel-core/register app.js\r\n\r\n    "}}
{"actor":{"display_login":"loganfsmyth"}}