I would like update my Babel config to version 7 in Electron project.
I've add my all plugins i needed :
"devDependencies": {
"@babel/cli": "^7.0.0-beta.40",
"@babel/core": "^7.0.0-beta.40",
"@babel/node": "^7.0.0-beta.40",
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.40",
"@babel/plugin-proposal-decorators": "^7.0.0-beta.40",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.40",
"@babel/plugin-proposal-optional-chaining": "^7.0.0-beta.40",
"@babel/plugin-transform-async-to-generator": "^7.0.0-beta.40",
"@babel/polyfill": "^7.0.0-beta.40",
"@babel/preset-env": "^7.0.0-beta.40",
"@babel/preset-react": "^7.0.0-beta.40",
"babel-eslint": "^7.1.1",
The compilation is good, but when Electron run my main.js
(compiled), i've this error :
A JavaScript error occurred in the main process
Uncaught Exception:
ReferenceError: regeneratorRuntime is not defined
I've try to install regeneratorRuntime
module, but no result.
Babel includes a polyfill that includes a custom regenerator runtime and core-js. This will emulate a full ES2015+ environment (no < Stage 4 proposals) and is intended to be used in an application rather than a library/tool. (this polyfill is automatically loaded when using babel-node ).
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 .
babel-runtime is a package that contains a polyfill and many other things that Babel can reference. You'd install it in your app with npm install babel-runtime. transform-runtime is a Babel plugin to process your source code and inject import foo from "babel-runtime" statements so that babel-runtime is actually used.
How we can do it without .babelrc (just using webpack config file)?. This error is caused when async/await functions are used without the proper Babel plugins. To install @babel/plugin-transform-runtime by typing in the command line,
You have used at least one of these features and it's not supported in at least one of your target s ( ['last 2 versions', 'ie >= 9'] ): As a result, @babel/preset-env decides to use @babel/plugin-transform-regenerator, which relies on regeneratorRuntime being available globally.
This error is caused when async/await functions are used without the proper Babel plugins. To install @babel/plugin-transform-runtime by typing in the command line, npm install --save-dev @babel/plugin-transform-runtime Then Add the plugin to pakage.json file in plugins array.
If you use @babel/runtime only for the Babel helpers, it doesn't "conflict" with @babel/polyfill. Sorry, something went wrong. thx @nicolo-ribaudo, I thought both were mutually exclusive.
hey I ran into the same problem and I am using Babel 7, for me I installed these two dependencies:
npm install --save @babel/runtime
npm install --save-dev @babel/plugin-transform-runtime
And, in .babelrc, add:
{
"presets": ["@babel/preset-env"],
"plugins": [
["@babel/transform-runtime"]
]
}
and this solved my problem
You should import the Babel Polyfill in your code:
import "@babel/polyfill";
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