Does Electron support ES6?


I just started fiddling around with Electron, and was wondering how to use ES6 features, I tried this in main.js, but it didn’t seem to work.

mainWindow.on('closed', () => {
    mainWindow = null;


You’ll have to use babel


Woulnd’t it be possible to compile against another io.js version?


I am not sure about accessing ES6 features on electron, because as far as I remember, I was able to use generators just by typing them without using babel. I am not sure about other features, though… What exactly is the error with your snippet above?


This is the error

App threw an error when running [SyntaxError: /Users/USER/www-local/my-app/main.js:38
  mainWindow.on('closed', () => {
Unexpected token )]


That page doesn’t mention anything about arrow functions, so I think io.js doesn’t support them yet. You can use this table to see which features are already supported by default in io.js. For the others you’ll have to use babel or another transpiler.


Yea that’s indeed the issue, thanks for pointing it out!


is that code on you main js page, as in the starter that is initially called (app.js), as this cannot be done in ES2015/6 but other files can, i have done some ES2015/6 test as i was wondering as well and alls fine.

Im using gulp, browserify & babelify for my test with vuejs and react js.

my react is not up jet, but hope this helps


It was code in main.js yes. The main reason I like Electron is because I don’t have to worry about transpiling code to work in all browsers :slight_smile: So Babel is no option. But I did figure out that arrow functions just aren’t supported yet :smile:


It’s been almost a year.

Does Electron support ES6 on the main thread?

Node 6 has great ES6 support.


Latest electron is based on Chrome 51 which supports ~98% of ES6.


What about the Node part?

It seems Electron includes Node 6 but this throws an error:

import app from 'app’
import BrowserWindow from ‘browser-window’


ES6 modules are not implemented in either Node 6 or Chrome 51 so Electron also does not support them.


Oh right…



of course electron supports ES6, at least the latest version as support, chromium 51 as 98% of compatibility


It’s possible to use Babel in Electron.

Simplest solution possible: babel-register hook:

this and .babelrc file with presets you want (es2015, react, whatever you need).


As Electron has been upgraded to more recent versions of Node.js and Chromium, you might not need babel anymore. You definitely do not have to install the bloated babel-preset-es2015 anymore, though. You can use babel-preset-electron instead.


you might not need babel anymore.
It depends what features you need.

I have the code which uses ES6 modules and they are still not supported AFAIK.

but I’ll take a look on this babel-preset-electron. It seems that it removes unnecessary transforms from ES2015 preset:
So I’ll probably switch to this instead using ES2015 preset.


We’re now in 2018, it doesn’t seem like electron supports import statements yet.

I’m using -r babel-register on the command line but still running into issues when loading a preload script when creating a new BrowserWindow.