I am using Parcel to bundle my project and jest to run my tests.
Everything works fine, but on tests that I have the async/await
keyword, I had to import regenerator-runtime/runtime
Like this:
import "regenerator-runtime/runtime"
test("read armored key", async() => {
})
And this work.
But without this import (import "regenerator-runtime/runtime"
) I got this error message:
ReferenceError: regeneratorRuntime is not defined
How can I change my project to run without this import on tests with async?
Example: https://github.com/skhaz/parcel-regeneratorRuntime-is-not-defined
Depending its version, not all features available in your browser runtime will work in the Node runtime. Promises (with await/async
) are supported in current versions of node, but since you are using Parcel, which by default uses Babel, your async/await
calls will be compiled to use regenerator-runtime
, a polyfill for that functionality. You can either import "regenerator-runtime/runtime"
in every entry file (not recommended if you don't need the polyfill!), or you can tell babel what your runtime is.
You should be able to get it to work with the @babel/preset-env preset, configured like so in your .babelrc
:
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "10" // the target node version, boolean true, or "current".
}
}
]
]
}
See this Medium article for more information about configuring babel for this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With