Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to compile JSX #21

Closed
javajosh opened this issue Jan 12, 2016 · 2 comments
Closed

Unable to compile JSX #21

javajosh opened this issue Jan 12, 2016 · 2 comments

Comments

@javajosh
Copy link

Well, okay, maybe if I post this problem I'll figure it out, too. So it looks like compilation is failing on line 7 (an invalid token failure, telling me that the inline JSX is the problem).

11 Jan 16:10:23 - error: Compiling of 'app/bar.jsx' failed. app/bar.jsx: Unexpected token (7:11)

Here is the content of bar.jsx:

var React = require('react');
var ReactDOM = require('react-dom');


var HelloMessage = React.createClass({
  render: function() {
    return <div>Hello {this.props.name}</div>;
  }
});

//hello
ReactDOM.render(
  <HelloMessage name="John" />,
  document.getElementById('container')
);

Here is my brunch config:

exports.config =
  # See http://brunch.io/#documentation for docs.
  files:
    javascripts:
       joinTo:
        'js/app.js': /^app/
        'js/vendor.js': /^(node_modules|vendor|bower_components)/
    stylesheets:
      joinTo: 'app.css'
    templates:
      joinTo: 'app.js'
  plugins:
    babel:
      presets: ['es2015']
      ignore: [
        /^(bower_components|vendor)/
        'app/legacyES5Code/**/*'
      ]
      pattern: /\.(es6|jsx)$/
@javajosh
Copy link
Author

Okay, so I'm still not really sure what I'm doing, but doing this seemed to fix the immediate problem:

npm install --save babel-preset-react

But another problem arises at runtime when I get one of these errors:

Uncaught Error: Cannot find module "react" from "bar"

Clearly it's a missing dependency. But I'm actually a little confused about whether this should be considered a runtime or a compile-time dependency, and how it should be installed. And yes I've looked for a complete example of brunch with react, but they all use the react-brunch plugin which (according to it's own website) is deprecated. :(

@javajosh
Copy link
Author

Aha, I figured it out. Brunch is very slick, but could definitely use some more docs. One thing that bit me, as trivial as it may seem, was that I had a locally installed copy in my project that was shadowing my (more recent) globally installed brunch - which had the npm support I wanted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant