jircdeveloper
jircdeveloper

Reputation: 434

Error parsing Es6 jsx to js React

I trying to work with react. I have the next code :

index.js

var Btn = require('./components/Btn.jsx');



    var app = {
        // Application Constructor
        initialize: function() {
            console.log("here with me");
            ReactDOM.render(<Btn>, document.getElementbyId('app'))
        },

        onDeviceReady: function() {
            this.receivedEvent('deviceready');
        },
    };

    app.initialize();

I have the next node_modules instaled:

Mi .babelrc

{ "presets": ["env"] }

When I run the comand for whath and compile the jsx to js I have the next

$ babel --presets env js/src --watch --out-dir js/dist    
SyntaxError: js/src/index.js: Unexpected token (10:24)
       8 |     initialize: function() {
       9 |         console.log("here with me");
    > 10 |         ReactDOM.render(<Btn/>, document.getElementbyId('app'))
         |                         ^
      11 |     },
      12 |
      13 |     onDeviceReady: function() {

I really find about this and try a lot of things but i don't undestand what happen, in each tutorial that i see the sintax is correct and all works good. I hope that this can be something stupid and I can't found it. Can Anyone explain to me What can i do? or how.

Upvotes: 0

Views: 161

Answers (1)

oobgam
oobgam

Reputation: 1309

Since you have babel-preset-react, try adding this to your .babelrc {"presets": ["react", "es2017"], } check this link for the format .babelrc

Upvotes: 1

Related Questions