reactjs / react-php-v8js

PHP library that renders React components on the server
Other
1.33k stars 127 forks source link

Trouble getting a simple component to render #25

Closed dotstormz closed 8 years ago

dotstormz commented 8 years ago

Error is as follows:

V8Js::compileString():19434: ReferenceError: module is not defined

PHP Test file is as follows:

include('../vendor/autoload.php');

$reactSource = file_get_contents('../node_modules/react/dist/react.js');
$appSource = file_get_contents('../app/Resources/js/components/Test.js');

$rjs = new \ReactJS($reactSource, $appSource);
$rjs->setComponent('Test', []);

echo '<div id="here">' . $rjs->getMarkup() . '</div>';

Javascript Component is as follows:

const Test = React.createClass({
    render: function() {
        return React.createElement('div', {}, 'Hello, World')
    }
})

module.exports = Test;

Are you able to shed any light as to why module is not available here? Thanks for your time.

zpao commented 8 years ago

You aren't in a CommonJS environment so module isn't defined. You should be able to leave off that entire line since Test will be a global in the context.