Arian Hosseinzadeh Arian Hosseinzadeh - 21 days ago 6
Node.js Question

Getting rid of node-jsx

In the router of my NodeJS app, I want to render a react app. As it is not browserified (and there reactified) it returns

unexpected token <
error while building. I found if I
require("node-jsx").install()
it doesn't return me this error.
But
node-jsx
is deprecated. Is there any way to build the project without requiring it ?

var JSX = require('node-jsx').install(),//as we don't reactify it while building
React = require('react'),
Board = React.createFactory(require('../components/board')),
DataStore = require('../store/store');


var router = require('express').Router();

router.get('/', function(req, res) {
var initialState = {'users': DataStore.getUsers()};
var markup = React.renderToString(
Board(initialState)
);
res.render('board', {
markup: markup,
state: JSON.stringify(initialState),
layout: 'boardLayout'
});
});

module.exports = router;

Answer

node-jsx has been deprecated in favor of babel. Instead of require('node-jsx').install();, you can now userequire('babel/register');.