0

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:

  • Babel
  • Babel-plugin-transform-react-jsx
  • Babel-preset-env
  • Babel-cli
  • babel-preset-env
  • babel-preset-es2017
  • babel-preset-react

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.

3
  • I think it has to do with transpiling react element. Add "transform-react-jsx" plugin to your .babelrc file Commented Jan 6, 2017 at 15:00
  • Sorry, How can i do that? Only add this item to the array? Commented Jan 6, 2017 at 16:00
  • Like this: "plugins": [ ["transform-react-jsx"] ] Commented Jan 6, 2017 at 16:02

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for answer. yap! this was an error, but it's not the error from the console, i fix that and the console still showing the same "unexpect token"
since you have babel-preset-react, try adding this to your .babelrc {"presets": ["react", "es2017"], } check this link for the format babeljs.io/docs/usage/babelrc
Your comment was the asnwer for my problem. very thanks. How can I mark this comment as my asnwer ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.