1

I have a helloworld.jsx file built successfully into a js file and is included in a page through the script tag.

When I run the page in Chrome, I get the following error. Should I include any other Bower package to use require.

Uncaught ReferenceError: require is not defined

var React = require('react');

var HelloWorld = React.createClass({displayName: "HelloWorld",
    render: function () {
        return (React.createElement("h1", null, "Hello World"));
    }
});

var parent = document.querySelector('#greeting');
React.renderComponent(React.createElement(HelloWord, null), parent);
2
  • 1
    Do you have webpack/browserify or some other package manager setup? If not you should just use a script tag or look at setting one up. Commented Jul 26, 2015 at 5:33
  • I directly dropped the reference to the react.js file which is working. I don't have webpack/browserify installed, but installed babel. But still giving the error, so I assume I have to install RequireJS? Commented Jul 26, 2015 at 12:00

1 Answer 1

1

Take a look into getting started and see how to setup React for use in browser: http://facebook.github.io/react/docs/getting-started.html

In order to use require you need to setup browserify/webpack compilation in your development process, both of them properly transform require into single bundle file.

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

Comments

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.