2

It would appear that in my adaptation of react-server-example (https://github.com/mhart/react-server-example) I cannot seem to use JSX. I have since made some changes (like replace Browserify with Webpack and so forth) however, after extensive looking around and installing babel-present-react, I can't seem to figure out what I am missing in order to run the app.

package.json

{ "name": "react-server-example", "version": "1.1.5", ... "dependencies": { "babel-preset-react": "^6.5.0", "react": "^0.14.7", "react-dom": "^0.14.7" }, "devDependencies": { "babel-cli": "^6.6.5", "babelify": "^7.2.0", "webpack": "^1.12.14" } } 

Errors when trying to run node

webpack.config.js

module.exports = { entry: "./entry.js", output: { filename: "bundle.js" }, module: { loaders: [ { test: /\.css$/, loader: "style!css" }, { test: /\.js$/, loader: "jsx-loader" }, { test: /\.js$/, exclude: /node_modules/, loader: "babel", query: { presets:['react'] } } ] } }; 

.babelrc

{ "presets": ["es2015", "stage-0", "react"] } 
11
  • You could look into express-react-views, which uses Babel to render React views on the server, much like any other template engine, such as Jade. Commented Mar 6, 2016 at 4:37
  • Can you also share how you've configured babel and how you're using babel to process the file? Commented Mar 6, 2016 at 4:37
  • so I have added a .babelrc file but I haven't done anything else with Babel... Commented Mar 6, 2016 at 4:47
  • 1
    What you may be missing is the use of Babel, as Node won't use Babel itself. You have to either compile the file from JSX to ES/JS before executing it (babel server.jsx -o server.js; node server.js) or use Babel's own command for doing both steps in one (babel-node server.js). Commented Mar 6, 2016 at 4:47
  • 1
    For that, you'll have to also install babel-preset-es2015. Or, remove "es2015" from any "presets" collections (.babelrc?). Commented Mar 6, 2016 at 4:53

1 Answer 1

-1

It should be:

render: function() { return ( <Test name="wassuppp" /> ); } 

You seem to be missing an opening (for the return.

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

3 Comments

I don't believe this will work in Javascript... (But if it works in Node, never mind)
nice catch but return <element />; is valid, so are parenthesis.
This is not correct. The parentheses are syntactic dressing, but are not required. @JohnDoe is correct.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.