2

I am able to transpile ES6 with babel but when I tried to test generators, I got this exception. Uncaught ReferenceError: regeneratorRuntime is not defined

I looked around and found out that I have to add bable-generator and runtime plugins. I added them as you can see from package.json but still getting this error.

I am running babel cli "npm run watch" which compiles my code and I can run it in the browser. I have a feeling that I am missing a step :)

{
  "devDependencies": {
    "babel-cli": "^6.14.0",
    "babel-plugin-transform-regenerator": "^6.14.0",
    "babel-plugin-transform-runtime": "^6.15.0",
    "babel-preset-es2015": "^6.14.0"
  },
  "scripts": {
    "build": "babel src -d output",
    "watch": "babel src --watch -d output"
  },
  "dependencies": {
    "babel-polyfill": "^6.13.0",
    "babel-runtime": "^6.11.6"
  }
}

{
  "presets": ["es2015"]
}
Yasin Yaqoobi
  • 1,888
  • 3
  • 27
  • 38
  • 1
    Do you also load the Babel polyfill in your source? – robertklep Sep 01 '16 at 20:46
  • 1
    @robertklep, nope that was the issue :). Thank you. – Yasin Yaqoobi Sep 01 '16 at 20:52
  • You'd generally use either `babel-polyfill` or `babel-runtime` but not both FYI. You've got `babel-plugin-transform-runtime` in your package, but haven't enabled it in your `.babelrc`, so doing that would also fix this issue. – loganfsmyth Sep 01 '16 at 21:31
  • @loganfsmyth Got it. I am running this in the browser. How would I enable babel-runtime in the .babelrc to run in the browser. Tried it earlier and it added bunch of requires to the transpiled file, which the browser doesn't recognize. – Yasin Yaqoobi Sep 01 '16 at 23:03
  • `babel-runtime` is a module, so for it to work in the browser, you'd have to use Babel via Browserify. – loganfsmyth Sep 01 '16 at 23:20

0 Answers0