-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async functions producing an error "ReferenceError: regeneratorRuntime is not defined" #5085
Comments
Hey @just-boris! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
Not sure how we would do that. Right now you either need transform-runtime or the polyfill. I dont think we can decide that for you. If we did it by default it would be a separate wrapper tool |
Does that mean that |
No like mentioned you can use the polyfill http://babeljs.io/docs/usage/polyfill. Also you can use async-to-gen plugin which transforms to generators (native) |
@hzoo With use in Node.js, if the module which requires The only workaround I've found is to relocate the code containing the |
Yeah generally I recommend
to initialize everything. @boneskull Keep in mind that don't recommend that libraries load |
going to close ^ is the recommendation, otherwise same as #4169 |
Hold on. If I write import 'babel-polyfill';
async function foo() {} the function is hoisted before the |
Function declarations are hoisted before imports are processed. Generally we recommend doing something like
if you need to use async functions in your app root. |
@loganfsmyth I understand that's how it works today. But should it? (Should I open a separate issue for this?) |
I found a different workaround, which is to configure Babel with {
"presets": [
["env", {
"modules": false
}]
]
} and rely on Webpack’s native Perhaps this is a stronger argument that Babel should also do such hoisting with the default |
That's probably reasonable in this case.
The interaction here is confusing and has a few cases. That said, either way I agree with you that getting the error your getting, just by declaring the code this way, is poor handling on our part. Changing the behavior of imports in our case would not be the right fix, but there is a fix we could do that we haven't done yet, which we probably should. |
This might be a dumb question, (I don't think I 100% understand how babel works) but why doesn't adding a |
@Flaque The async-to-generator and transform-regenerator plugins are already assumed to be in use here, else we wouldn’t be talking about |
Reopened as #6956. |
@hzoo what does it mean if I'm using var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator); but also includes this statement with the wrong variable name, producing a type error? var _marked = /*#__PURE__*/_regeneratorRuntime.mark(getShifts); This file was not having problems before I made some changes, and another file in the same directory gets transpiled correctly, so something is very screwy: var _marked2 = /*#__PURE__*/_regenerator2.default.mark(getShiftsCore); |
@hzoo I'm pretty sure that that babel 6 has a bug when all one generator does is |
Update your If you are using
or if you are using
|
This is necessary to be able to use async/await functions, otherwise we get this error in the console at runtime: ReferenceError: regeneratorRuntime is not defined See: <babel/babel#5085>
These babel bugs are encountered when used in the Karma tests: babel/babel#6956 babel/babel#5085 Just explicitly return a Promise instead.
In my case installing babel-plugin-transform-runtime solved my issues:
Then, in {
"plugins": [
["transform-runtime", {
"polyfill": false,
"regenerator": true
}]
]
} |
Input Code
Babel Configuration (.babelrc, package.json, cli command)
Expected Behavior
I expect that the code will run just fine
Current Behavior
It produces the following code, which throws an error
ReferenceError: regeneratorRuntime is not defined
Possible Solution
When I have added
transform-runtime
plugin it also added a require statementbabel-runtime/regenerator
and the code was run well. But I believe that babel-preset-latest should work at it is, without additional configuration.Your Environment
The text was updated successfully, but these errors were encountered: