3

任何信息都会很有帮助,最初我也运行了 npm install babel-loader 命令。

我有

./app-client.js 中的错误模块构建失败:SyntaxError:/Users/dawatramani/ReactNodejs/app-client.js:

意外令牌 (4:13)

  2 | var APP= require('./components/APP');
  3 | 
> 4 | React.render(<APP />,document.getElementById('react-container'));
    |              ^
  5 | 

在 Parser.pp.raise (/Users/dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/location.js:22:13) 在 Parser.pp.unexpected (/Users/dawatramani/ReactNodejs/ node_modules/babel-core/node_modules/babylon/lib/parser/util.js:89:8) 在 Parser.pp.parseExprAtom (/Users/dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/ expression.js:522:12) 在 Parser.pp.parseExprSubscripts (/Users/dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:277:19) 在 Parser.pp.parseMaybeUnary (/Users/dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:257:19) 在 Parser.pp.parseExprOps (/Users/dawatramani/ReactNodejs/node_modules/babel-core/ node_modules/babylon/lib/parser/expression.js:188:19) 在 Parser.pp。parseMaybeConditional (/Users/dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:165:19) 在 Parser.pp.parseMaybeAssign (/Users/dawatramani/ReactNodejs/node_modules/babel-core /node_modules/babylon/lib/parser/expression.js:128:19) 在 Parser.pp.parseExprListItem (/Users/dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:1046 :16) 在 Parser.pp.parseCallExpressionArguments (/Users/dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:353:20) 在 Parser.pp.parseSubscripts (/Users/dawatramani /ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:316:31)在 Parser.pp。parseExprSubscripts (/Users/dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:287:15) 在 Parser.pp.parseMaybeUnary (/Users/dawatramani/ReactNodejs/node_modules/babel-core /node_modules/babylon/lib/parser/expression.js:257:19) 在 Parser.pp.parseExprOps (/Users/dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:188 :19) 在 Parser.pp.parseMaybeConditional (/Users/dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:165:19) 在 Parser.pp.parseMaybeAssign (/Users/dawatramani /ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:128:19) 在 Parser.pp.parseExpression (/Users/dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib /parser/expression.js:92:19) 在 Parser.pp.parseBlockBody (/Users/dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:163:19) ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:529:21) 在 Parser.pp.parseTopLevel (/Users/dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/ parser/statement.js:36:8) 在 Parser.parse (/Users/dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/parser/index.js:129:19) 在 parse (/Users/ dawatramani/ReactNodejs/node_modules/babel-core/node_modules/babylon/lib/index.js:47:47) 在 File.parse (/Users/dawatramani/ReactNodejs/node_modules/babel-core/lib/transformation/file/index. js:517:34) 在文件中。parseCode (/Users/dawatramani/ReactNodejs/node_modules/babel-core/lib/transformation/file/index.js:603:20) 在/Users/dawatramani/ReactNodejs/node_modules/babel-core/lib/transformation/pipeline.js :49:12 在 File.wrap (/Users/dawatramani/ReactNodejs/node_modules/babel-core/lib/transformation/file/index.js:563:16) 在 Pipeline.transform (/Users/dawatramani/ReactNodejs/node_modules/ babel-core/lib/transformation/pipeline.js:47:17) 在 Object.module.exports (/Users/ dawatramani/ReactNodejs/node_modules/babel-loader/index.js:88:12)在 Pipeline.transform (/Users/dawatramani/ReactNodejs/node_modules/babel-core/lib/transformation /pipeline.js:47:17) 在转换 (/Users/dawatramani/ReactNodejs/node_modules/babel-loader/index.js:14:22) 在 Object.module.exports (/Users/dawatramani/ReactNodejs/node_modules/babel -loader/index.js:88:12)在 Pipeline.transform (/Users/dawatramani/ReactNodejs/node_modules/babel-core/lib/transformation /pipeline.js:47:17) 在转换 (/Users/dawatramani/ReactNodejs/node_modules/babel-loader/index.js:14:22) 在 Object.module.exports (/Users/dawatramani/ReactNodejs/node_modules/babel -loader/index.js:88:12)

4

2 回答 2

2

reactJS好吧,您不应该使用当前版本,React.render()而应该使用ReactDOM.render()and import ReactDOM from "react-dom"。我认为这将解决您的问题。

ReactDOM.render(<ComponentName />,document.getElementById('react-container'));

这是 0.14 引入的最新更改。React 现在分为核心库和 DOM 适配器。现在通过 ReactDOM.render 完成渲染。

文档

于 2016-07-21T07:05:38.037 回答
0

好像你忘了在渲染方法中粘贴一个组件:)

React.render(,document.getElementById('react-container'));
于 2016-07-21T06:09:56.407 回答