My express's app.js loads in my main template file like this:
app.get('/', routes.index);
Where routes.index
is:
exports.index = function(req, res){
res.render('Index', { title: 'Express' });
};
My Index.jsx is my main template which looks like this:
import React from 'react';
import Layout from './layout';
import NetworkCanvas from '../lib/components/NetworkCanvas/Canvas.jsx';
class Index extends React.Component {
render() {
return (
<html>
<head>
<title>{this.props.title}</title>
</head>
<body>
<NetworkCanvas />
</body>
</html>
);
}
}
However, when my localhost:8000 loads I keep getting the error:
/MyWebpage/lib/components/NetworkCanvas/Canvas.jsx:1
(function (exports, require, module, __filename, __dirname) { import React from 'react';
^^^^^^
SyntaxError: Unexpected token import
How is it possible that the import
statements in my Index.jsx work but the ones in the subcomponent don't?
Note that I'm using express-react-views
for my express engine.
Edit: Here's my Canvas.jsx:
import React from 'react';
class Canvas extends React.Component {
constructor() {
this.state = {
width: '0',
height: '0'
}
}
render() {
return (
<canvas
width={this.state.width}
height={this.state.height}
ref={(el) => {this.canvas = el}}>
</canvas>
);
}
}
export default Canvas;
Edit 2:: Here is my project. Thanks all for the help!