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:
I found this answer to my troubles and it worked when I implemented it.
Opinion:
Don't rely on zero-configuration tools like Parcel: they end up adding to your development time by creating unexpected behavior (like your issue), or you have to spend time learning how it works. It's enough to debug your own application; you shouldn't have to debug your build tool as well.