I'm getting an SyntaxError: Unexpected token ")"
on Safari only - this code works on every other browser.
I'm using gulp
to compile my files as follows:
browserify(componentPath + "app.jsx")
.transform(reactify)
.transform(babelify)
.bundle()
.pipe(source('app.js'))
.pipe(gulp.dest(buildPath));
The syntax error is highlighting the following:
return React.createElement(If, {
condition: !_.isEmpty(title)
}, React.createElement("div", {
className: "row wrapper border-bottom white-bg page-heading"
}, React.createElement("div", {
className: "col-lg-9"
}, React.createElement("h2", null, title || 'Untitled'), React.createElement("ol", {
className: "breadcrumb"
}, React.createElement("li", null, React.createElement("a", {
onClick: () => self.history.pushState(null, home)
}, "Home")), links.map(function(link, index) {
var url = link.url;
return React.createElement("li", {
onClick: () => self.history.pushState(null, url),
key: url,
className: "ptr-click"
}, index == links.length - 1 ? React.createElement("strong", null, link.title || 'Untitled') : link.title);
})))));
I commented the whole section out, just to see if it is this particular block of code, but then the error referred to another block of exactly the same React.createElement
.
Taking mattclemens comment into consideration, Safari currently does not execute arrow functions. So I updated my gulp
script to:
browserify(componentPath + "app.jsx")
.transform(reactify)
.transform(babelify, {presets: ["es2015", "react"]})
.bundle()
.pipe(source('app.js'))
.pipe(gulp.dest(buildPath));
Of course, don't forget to install the presets:
npm install babel-preset-es2015 babel-preset-react
This worked perfectly, and now my code runs on Safari as well :)
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