如何在ES6 React代码中使用Express React视图库

时间:2018-08-31 19:29:30

标签: node.js reactjs express

我试图将express-react-views用作Express View引擎,但是它只在没有ES6的JSX中编译React代码。我该如何切换到ES6。

这是我用于“错误”页面的代码:

import React, { Component } from "react";

class Error extends Component {
  render() {
    return <p>{this.props.error}</p>;
  }
}

export default Error;

这是我的错误:

    SyntaxError: /Users/mac/Documents/ReactJS-dev/test/views/error.jsx: Unexpected token (4:8)
[0m [90m 2 | [39m
 [90m 3 | [39m[36mclass[39m [33mError[39m [36mextends[39m [33mComponent[39m {
[31m[1m>[22m[39m[90m 4 | [39m  state [33m=[39m {}[33m;[39m
 [90m   | [39m        [31m[1m^[22m[39m
 [90m 5 | [39m  render() {
 [90m 6 | [39m    [36mreturn[39m [33m<[39m[33mp[39m[33m>[39m{[36mthis[39m[33m.[39mprops[33m.[39merror}[33m<[39m[33m/[39m[33mp[39m[33m>[39m[33m;[39m
 [90m 7 | [39m  }[0m
    at Parser.pp$5.raise (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:4454:13)
    at Parser.pp.unexpected (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:1761:8)
    at Parser.pp$1.parseClassProperty (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:2571:50)
    at Parser.parseClassProperty (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:6157:20)
    at Parser.pp$1.parseClassBody (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:2516:34)
    at Parser.pp$1.parseClass (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:2406:8)
    at Parser.pp$1.parseStatement (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:1843:19)
    at Parser.parseStatement (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:5910:22)
    at Parser.pp$1.parseBlockBody (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:2268:21)
    at Parser.pp$1.parseTopLevel (/Users/mac/Documents/ReactJS-dev/test/node_modules/babylon/lib/index.js:1778:8)

0 个答案:

没有答案