[英]Error parsing Es6 jsx to js React
我嘗試與之合作。 我有下一個代碼:
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();
我安裝了下一個node_modules:
Mi .babelrc
{ "presets": ["env"] }
當我運行comand whath並將jsx編譯為js時,我得到了下一個
$ 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() {
我真的發現了這個問題並嘗試了很多事情,但是我不理解發生了什么,在每個教程中,我都看到了sintax是正確的,並且一切正常。 我希望這可能是愚蠢的,但我找不到。 誰能向我解釋我該怎么辦? 或如何。
由於您具有babel-preset-react
,請嘗試將其添加到您的.babelrc {"presets": ["react", "es2017"], }
presets {"presets": ["react", "es2017"], }
檢查此鏈接的格式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.