Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regeneratorRuntime is not defined for nodeJS transpiled babel

I am getting the following error:

ReferenceError: regeneratorRuntime is not defined

and it is caused by

_asyncToGenerator(regeneratorRuntime.mark(function _callee() {

I have tried the methods in Babel 6 regeneratorRuntime is not defined with async/await and also RegeneratorRuntime is not defined, but have no luck.

My .babelrc is as below

{
  "presets":["latest"]
}

I am able to solve the problem by add require('babel-polyfill') however this line will throw problem if I run it with babel-node during development time.

Anyone faced similar problem before?

like image 941
drhanlau Avatar asked Apr 24 '26 21:04

drhanlau


1 Answers

Add babel-polyfill to your plugins in the .babelrc file:

{
  "presets": [["es2016"]],
  "plugins": ["syntax-async-functions","transform-regenerator","babel-polyfill"],
}
like image 67
Alex Avatar answered Apr 27 '26 03:04

Alex