2016-07-12 3 views
1

私はいくつかのコンテンツをレンダリングする簡単な反応アプリを作成しようとしています。反応しWebPACKの、より一層のパッケージの必要な依存関係をインストールしたのですが、どれも実行している時に単純なReact.render()はエラーを返します

var React = require('react'); 

var APP = React.createClass({ 
render: function(){ 
    return(<h1>Hello React</h1>); 
} 
}); 

module.exports = APP; 

アプリ-client.jsファイル

var React = require('react'); 
var APP = require('./components/APP'); 

React.render(<APP />, document.getElementById('react-container')); 

を提出私のAPP.jsで

を働いていませんコマンドwebpackエラー:

ERROR in ./app-client.js 
Module build failed: SyntaxError: /Users/akash/Dropbox/learning/pollingApp/start/app-client.js: Unexpected token (4:13) 
2 | var APP = require('./components/APP'); 
3 | 
> 4 | React.render(<APP />, document.getElementById('react-container')); 
    |   ^
at Parser.pp.raise (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/location.js:22:13) 
at Parser.pp.unexpected (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/util.js:89:8) 
at Parser.pp.parseExprAtom (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:522:12) 
at Parser.pp.parseExprSubscripts (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:277:19) 
at Parser.pp.parseMaybeUnary (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:257:19) 
at Parser.pp.parseExprOps (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:188:19) 
at Parser.pp.parseMaybeConditional (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:165:19) 
at Parser.pp.parseMaybeAssign (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:128:19) 
at Parser.pp.parseExprListItem (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:1046:16) 
at Parser.pp.parseCallExpressionArguments (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:353:20) 
at Parser.pp.parseSubscripts (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:316:31) 
at Parser.pp.parseExprSubscripts (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:287:15) 
at Parser.pp.parseMaybeUnary (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:257:19) 
at Parser.pp.parseExprOps (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:188:19) 
at Parser.pp.parseMaybeConditional (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:165:19) 
at Parser.pp.parseMaybeAssign (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:128:19) 
at Parser.pp.parseExpression (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/expression.js:92:19) 
at Parser.pp.parseStatement (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/statement.js:163:19) 
at Parser.pp.parseBlockBody (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/statement.js:529:21) 
at Parser.pp.parseTopLevel (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/statement.js:36:8) 
at Parser.parse (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/parser/index.js:129:19) 
at parse (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babylon/lib/index.js:47:47) 
at File.parse (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babel-core/lib/transformation/file/index.js:517:34) 
at File.parseCode (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babel-core/lib/transformation/file/index.js:603:20) 
at /Users/akash/Dropbox/learning/pollingApp/start/node_modules/babel-core/lib/transformation/pipeline.js:49:12 
at File.wrap (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babel-core/lib/transformation/file/index.js:563:16) 
at Pipeline.transform (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babel-core/lib/transformation/pipeline.js:47:17) 
at transpile (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babel-loader/index.js:14:22) 
at Object.module.exports (/Users/akash/Dropbox/learning/pollingApp/start/node_modules/babel-loader/index.js:88:12) 
+0

あなたはJSXを使用するつもりなら、あなたは、クライアント側のコンパイラが含まれるコードtranspileや、これに関する情報であるべきかのいずれかである必要があります[ここ](https://facebook.github.io/react/docs/jsx-in-depth.html)。これまでの両方の回答は、最も不正確で最悪の場合は間違っています。[開始する](https://facebook.github.io/react/docs/getting-started.html)ガイドも読んでみてください。彼らはあなたが勉強できるスターターキットも持っています。 – ivarni

答えて

1

react-domモジュールを使用すると、React Dom APIを使用する必要があります。 ReactDom.renderは現在、レンダリングのための新しいAPIに反応コンポーネント

var ReactDom = require('react-dom'); 
var APP = require('./components/APP'); 

ReactDom.render(<APP />, document.getElementById('react-container')); 
+1

あなたが回答として投稿しているコードに説明を追加すると、訪問者がなぜこれが良い答えであるかを理解するのに役立ちます。 – abarisone

関連する問題