简体   繁体   中英

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:

  • 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.

由于您具有babel-preset-react ,请尝试将其添加到您的.babelrc {"presets": ["react", "es2017"], } presets {"presets": ["react", "es2017"], }检查此链接的格式

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM