question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

choking on jsx syntax

See original GitHub issue

I’ve just updated babelify in order to get rid of reactify and hopefully fix the messed up sourcemaps I’ve been having. However, I was getting some trouble along the lines of

Unexpected token (13:1) while parsing file: ./client/scripts/index.jsx

I’ve installed the latest version of babelify (7.0.2), which includes babel-core 6.0.12.

My gulpfile:

'use strict';

const browserify = require('browserify');
const buffer     = require('vinyl-buffer');
const gulp       = require('gulp');
const gutil      = require('gulp-util');
const source     = require('vinyl-source-stream');
const sourcemaps = require('gulp-sourcemaps');
const watchify   = require('watchify');

gulp.task('scripts', () => {
    let bundler = browserify({
        debug: true,
        entries: './client/scripts/index.jsx',
        transform: [
            require('babelify')
        ]
    });

    bundler.on('log', (msg) => {
        gutil.log(gutil.colors.cyan('scripts') + ': ' + msg);
    });

    const bundle = () => {
        return bundler.bundle()
            .on('error', (err) => {
                console.error(err.message);
            })
            .pipe(source('app.js'))
            .pipe(buffer())
            .pipe(sourcemaps.init({ loadMaps: true }))
            .pipe(gutil.env.production ? require('gulp-uglify')() : gutil.noop())
            .pipe(sourcemaps.write('.'))
            .pipe(gulp.dest('./public/js'));
    };

    if (!gutil.env.production) {
        bundler = watchify(bundler);
        bundler.on('update', bundle);
    }

    return bundle();
});

gulp.task('default', [ 'scripts' ]);

And the ./client/scripts/index.jsx it’s choking on:

'use strict';

import { createStore } from 'redux';
import { Provider}     from 'react-redux';
import React           from 'react';
import ReactDOM        from 'react-dom';
import reducers        from './reducers';
import routes          from './routes.jsx';

const store = createStore(reducers);

ReactDOM.render((
    <Provider store={store}>{routes}</Provider>
), document.querySelector('[data-app]'));

Anything obvious I’m missing, or some config I should be using?

Cheers.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
wphamptoncommented, Feb 3, 2016

Under the section titled Plugin Presets from http://babeljs.io/blog/2015/10/29/6.0.0

You probably want npm install --save-dev babel-preset-react

Then use it as part of your Babelify options https://github.com/babel/babelify#options

4reactions
yannbertrandcommented, Mar 14, 2016

Summary:

Basically you just have to npm install the babel-preset-react preset and add 'react' to the babel presets:

babel({ presets: ['es2015', 'react'] })
Read more comments on GitHub >

github_iconTop Results From Across the Web

React render is choking on nested object in property
I have this react component. It is passed a prop called data. data is an object like { "title" : "some title", "meta"...
Read more >
Introducing JSX - React
It is called JSX, and it is a syntax extension to JavaScript. We recommend using it with React to describe what the UI...
Read more >
How to Work with and Manipulate State in React - SitePoint
To set the initial state, use this.state in the constructor with your ES6 class React.Component syntax. Don't forget to invoke super() with ...
Read more >
Install - Prettier
... format all tests in a directory (see fast-glob for supported glob syntax). ... (without mangling files you don't want, or choking on...
Read more >
prettier ignore
How to add ESLint and Prettier to a React TypeScript Project. ... more information. prettierignore uses gitignore syntax. gitignore file must be edited...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found