0

For a quick test, i've created my main.jsx file written in ES6 for my ReacJS app:

main.jsx

import React from 'react'
import { render } from 'react-dom'
import { Router, Route, Link } from 'react-router'

class TestComponent extends React.Component {

    render() {
        return <div className="test">...</div>;
    }

}

Then i compile my code with browserify and babel:

browserify -t babel main.jsx -o public/js/bundle.js 

I get this error: Error: Cannot find module 'babel'

What's the cleanest way to compile ES6 code with ReactJS?

1 Answer 1

1

If you are using Browserify, you can use the transform 'babelify' to compile your ES6 code. Check it out here:

https://github.com/babel/babelify

Sign up to request clarification or add additional context in comments.

3 Comments

I've installed babelify, i've launched browserify main.jsx -o public/js/bundle.js -t [ babelify --presets [ es2015 react ] ] but i get this error: Couldn't find preset "es2015" while parsing file
npm install babel-preset-es2015
Ok, babel-preset-es2015 and babel-preset-react was missing, thank you all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.