javascript - Electron and Babel 6 async / await throw unexpected token -


i want use async / await feature es7 in electron app, seems not working. gives me

syntax error: unexpected token function

after command npm start..

electron: v0.37.6 node: v5.11.0 stable windows 10 x64

main.js

'use strict';  require("babel-core/register"); require("babel-polyfill");  (async function() {   await console.log("test"); })() 

package.json (snipped)

"devdependencies": {   "babel": "^6.5.2",   "babel-cli": "^6.7.7",   "babel-core": "^6.7.7",   "babel-eslint": "^6.0.3",   "babel-plugin-syntax-async-functions": "^6.5.0",   "babel-plugin-transform-async-to-generator": "^6.7.4",   "babel-plugin-transform-regenerator": "^6.6.5",   "babel-polyfill": "^6.7.4",   "babel-preset-es2015": "^6.6.0",   "babel-preset-stage-3": "^6.5.0",   "electron-debug": "^0.6.0",   "electron-prebuilt": "^0.37.0",   "eslint": "^2.8.0" } 

.babelrc

{   "presets": ["es2015", "stage-3"],   "plugins": ["transform-async-to-generator", "syntax-async-functions", "transform-regenerator"] } 

have idea what's missing in conf etc. please?

edit

i've tried add import after require() ends with

unexpected token import

it seems babe not loaded @ all..

finally solved in 2 easy steps:

  1. puting babel stuff in seperate file

index.js

'use strict';  require('babel-core/register'); require("babel-polyfill"); require("./src/main"); 
  1. updated package.json execute on npm start

package.json

"scripts": {   "start": "electron index.js" }, 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -