I have a React.Component in app.js which I'm trying to render in Express.
app.js:
var React = require('react')
class App extends React.Component {
render () {
return <div>Hello</div>
}
}
export default App
server.js:
var ReactApp = React.createFactory(require('./public/js/bundle.js'))
console.log(ReactDOMServer.renderToString(ReactApp()))
If I use app.js (pre-browserify) to replace the contents of bundle.js, it works! I get the following React app in string form from Express.
<div data-reactid=".av7twqopa8" data-react-checksum="-111206364"><button data-reactid=".av7twqopa8.0">click me!</button></div>
BUT if I use browserify to generate bundle.js via app.js, it throws an error:
Error: Invariant Violation: Element type is invalid: expected a string
(for built-in components) or a class/function (for composite
components) but got: object.
The browserify command I'm using is:
"browserify": {
"transform": [ [ "babelify", { "presets": [ "es2015", "react" ] } ] ]
},
"scripts": {
"build": "NODE_ENV=production browserify src/main.js | uglifyjs -cm > public/js/bundle.js"