Tuesday, June 6, 2017

babel preset-env with electron & react

Leave a Comment

To create an electron & react application I was using the react and node7 presents as follows (which works)

  "babel": {     "sourceMaps": "inline",     "presets": [       "react",       "node7"     ]   }, 

But I wanted to go with something more future proof so I tried out the preset-env

  "babel": {     "sourceMaps": "inline",     "presets": [       [         "env",         {           "targets": {             "electron": "1.6.7"           },           "debug": true,           "useBuiltIns": true         }       ]     ]   }, 

However this is not working for me. It seems that es7 object spread is not being found, and there are issues with react JSX. What simple thing did I miss?

babel-preset-env: `DEBUG` option  Using targets: {   "electron": "1.6.7" }  Modules transform: commonjs  Using plugins:   syntax-trailing-function-commas {"electron":"1.6.7"}  Using polyfills:   es7.string.pad-start {"electron":"1.6.7"}   es7.string.pad-end {"electron":"1.6.7"}   web.timers {"electron":"1.6.7"}   web.immediate {"electron":"1.6.7"}   web.dom.iterable {"electron":"1.6.7"} src\dash\actions.js -> dist\dash\actions.js src\dash\actionTypes.js -> dist\dash\actionTypes.js SyntaxError: src/dash/dash.js: Unexpected token (29:18)   27 |     let stats = remote.getGlobal('DASH').stats   28 |     //stats.jobStats = (stats.jobStats == "") ? "0" : stats.jobStats  -- we only needed this if the folder was m issing > 29 |     let state = { ...STORE.getState().ServerStats }      |                   ^   30 |     let original = { ...state }   31 |     state.WatsonInstalled = (state.WatsonInstalled != stats.watsonInstalled) ? stats.watsonInstalled : state.Wat sonInstalled   32 |     state.WatsonRunning = (state.WatsonRunning != stats.watsonRunning) ? stats.watsonRunning : state.WatsonRunni ng SyntaxError: src/dash/reducers.js: Unexpected token (18:25)   16 |     switch (action.type) {   17 |         case A.SetUpdating: > 18 |             newState = { ...state, isUpdating: action.payload }      |                          ^   19 |             return newState   20 |         case A.SetChanger:   21 |             newState = { ...state, fieldName: action.payload } SyntaxError: src/jsx/Configuration.jsx: Unexpected token (19:4)   17 |     resetForm,   18 |     isUpdating, > 19 |     ...props }) => {      |     ^   20 |     COMPONENTS["Configuration"] = props // Register this component in the Dash Components list (so we can get th e change() function)   21 |     return (   22 |         <Form horizontal onSubmit={(e) => { alert('foobar'); handleSubmit(doSubmit) }}> SyntaxError: src/jsx/Controls.jsx: Unexpected token (7:8)    5 | const Control = ({ WatsonInstalled, WatsonRunning, FMERunning, buttonAction }) => {    6 |     return ( >  7 |         <Grid>      |         ^    8 |             <Row className="propRow">    9 |                 <Col sm={3}>   10 |                     <OverlayTrigger placement="bottom" SyntaxError: src/jsx/Dashboard.jsx: Unexpected token (12:4)   10 | const App = ({ GLVersion }) => {   11 |   return ( > 12 |     <Grid> |         ^    8 |             <Row className="propRow">    9 |                 <Col sm={3}>   10 |                     <OverlayTrigger placement="bottom" SyntaxError: src/jsx/Dashboard.jsx: Unexpected token (12:4)   10 | const App = ({ GLVersion }) => {   11 |   return ( > 12 |     <Grid>      |     ^   13 |       <Row className="versionRow">   14 |         <Col smOffset={10} sm={1} className="fieldLabel">Version:</Col>   15 |         <Col sm={1} className="fieldLabel">{GLVersion}</Col> SyntaxError: src/jsx/FieldInputs.jsx: Unexpected token (9:8)    7 | const FieldControl = ({ input, meta, type, min, max, tip, cid }) => {    8 |     return ( >  9 |         <OverlayTrigger placement="left" overlay={(<Tooltip id={cid + "-tip"}>{tip}</Tooltip>)}>      |         ^   10 |             <FormControl   11 |                 type={type}   12 |                 min={min} SyntaxError: src/jsx/Utilities.jsx: Unexpected token (9:8)    7 | const Util = ({ JobsDirSize, killAction }) => {    8 |     return ( >  9 |         <Grid>      |         ^   10 |             <Row className="propRow">   11 |                 <Col sm={3} className="fieldLabel">Job Folder Size:</Col>   12 |                 <Col sm={9} className="fieldLabel">{JobsDirSize} MB</Col> src\main\main.js -> dist\main\main.js src\main\monitor.js -> dist\main\monitor.js src\main\utils.js -> dist\main\utils.js src\main\watson.js -> dist\main\watson.js 

1 Answers

Answers 1

It turns out this is an open issue with this preset: https://github.com/babel/babel-preset-env/issues/326

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment