解析错误:基本的.js文件在EOF处出现意外的令牌“”

时间:2019-10-07 21:43:14

标签: javascript reactjs

在编译一个简单的React应用程序时,我在文件的最后(空白)行收到一条错误消息,说“意外令牌”

import { Link, Redirect } from "react-router-dom";
import './App.css';


class Companies extends Component {
    constructor(props) {
        super(props);
        var user = null;
        if (props.hasOwnProperty("user")){
            user = props["user"];
        }
        this.state = {
            user: user,
            companies: [],
        };
    }

}

export Companies

是我正在尝试运行的代码

Failed to compile.

./src/Companies.js
  Line 22:1:  Parsing error: Unexpected token

  20 |
  21 | export Companies
> 22 |
     | ^

是我收到的错误消息。

1 个答案:

答案 0 :(得分:1)

要导出类,正确的语法为:export default Class

尝试一下:

import { Link, Redirect } from "react-router-dom";
import './App.css';


class Companies extends Component {
    constructor(props) {
        super(props);
        var user = null;
        if (props.hasOwnProperty("user")){
            user = props["user"];
        }
        this.state = {
            user: user,
            companies: [],
        };
    }

}

export default Companies