I have an Electron 1.5 application, with some JSX components that I wrote. I want the components in a seperate file (module).
Given that Electron supports Node 7.4 and Chromium 54, I figured I could use ES6 module syntax, with export. But I am getting errors with the export command.
This note indicates that ES6 might have issues in Electron: ES6 syntax import Electron (require..)
export class Welcome extends React.Component {
render() {
return <h1>Hello Again, {this.props.name}</h1>;
}
}
export class CountWidget extends React.Component {
render() {
return (
<div>
<h1>{this.props.value}</h1>
<button onClick={this.props.onIncrement}>+</button>
<button onClick={this.props.onDecrement}>-</button>
</div>);
}
}
Do I require, or import in the main program:
import {Welcome} from 'componenets\widgets'
I am currently using VSCODE for my IDE, and I have a Babel watch process running that is with the react and es2016 presets running. I tried a es2015 preset, but Electron is not happy with the require syntax that babel uses.
"babel": {
"sourceMaps": "inline",
"presets": [
"react",
"es2016"
]
}
UPDATE
I tried using babel-presets-es2016-node5
It still complains of:
Uncaught ReferenceError: exports is not defined(…)
It generated this at the end of the Counter.js file, which is where it complains.
exports.Welcome = Welcome;
exports.CountWidget = CountWidget;