Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6 transformation not working #26

Open
martintietz opened this issue Dec 4, 2014 · 9 comments
Open

ES6 transformation not working #26

martintietz opened this issue Dec 4, 2014 · 9 comments

Comments

@martintietz
Copy link

Using this example file test.jsx:

class TestClass {
    testoutput() {
        console.log('Some text...');
    }
};

module.exports = TestClass;

Trying to require test.jsx from inside another file ...

require('node-jsx').install({ extension: '.jsx', harmony: true });

var test = require('./test.jsx');

test.testoutput();

... gives me the following error:

test.testoutput();
     ^
TypeError: undefined is not a function
@Jpunt
Copy link

Jpunt commented Feb 4, 2015

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 (

@gpbl
Copy link

gpbl commented Feb 5, 2015

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?

@Jpunt
Copy link

Jpunt commented Feb 5, 2015

Are you referring to @martintietz's example or mine? I've made mine a bit more clear. It should be possible this way, right?

@gpbl
Copy link

gpbl commented Feb 5, 2015

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.

@Jpunt
Copy link

Jpunt commented Feb 8, 2015

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?

@artisonian
Copy link

Both examples cited have syntax errors. See my gist for corrections.

@Jpunt
Copy link

Jpunt commented Feb 25, 2015

Ah, that makes sense. I'll try it out shortly, thanks! Can't wait for 0.13 to get out of beta though :)

@Jpunt
Copy link

Jpunt commented Feb 25, 2015

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!

@Jpunt
Copy link

Jpunt commented Feb 26, 2015

FYI: Babel.js saved the day for me: https://github.com/Jpunt/fluxible-offline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants