Open martintietz opened 9 years ago
This doesn't work for me either:
// app.js
require('node-jsx').install({ extension: '.jsx', harmony: true });
require('es6-component');
// es6-component.jsx
var ES6Component = React.createClass({
render() {
return (<div></div>);
}
});
Results in:
render() {
^
SyntaxError: Unexpected token (
I believe you need to require a .jsx in another module:
require('node-jsx').install({ extension: '.jsx', harmony: true });
require('./app');
// app.js
var test = require('./test.jsx');
test.testoutput();
does it work?
Are you referring to @martintietz's example or mine? I've made mine a bit more clear. It should be possible this way, right?
Both :) Now you require
a .jsx
in the same module where require('node-jsx').install
is placed. I think the "new" require is not yet enabled.
Try, instead, to require
another "normal" js module, into which you require
the .jsx
file (as in my example). I remember I had a similar issue i solved this way.
I don't get it. I require/install node-jsx from the root level in which I include some jsx later on. See this branch of my example of how I did this. This should work, right?
Both examples cited have syntax errors. See my gist for corrections.
Ah, that makes sense. I'll try it out shortly, thanks! Can't wait for 0.13 to get out of beta though :)
Writing it the way you've explained, this
refers to an empty object instead of the class it initiates (I'm working with fluxible, so I need to get the context from there). I guess I'll wait for 0.13 for proper ES6-support. Thanks anyway!
FYI: Babel.js saved the day for me: https://github.com/Jpunt/fluxible-offline
Using this example file
test.jsx
:Trying to require
test.jsx
from inside another file ...... gives me the following error: