react-collapsible无法编译

时间:2018-05-07 16:02:24

标签: javascript java reactjs dependencies react-component

我正在开发spring + reactJS项目,目前正在开发前端(此字段中的begginer)。

一般来说,我尝试用" REACT-COLLAPSIBLE"创建简单的手风琴。

代码非常简单:JS文件:

import React, { Component } from 'react';
import { Link } from "react-router-dom";
import '../index.css';
import Collapsible from "react-collapsible/src/Collapsible";


class Author extends Component {

    constructor(props) {
        super(props);
    }

    render() {
        return (

            <Collapsible trigger="Start here">
                <p>This is the collapsible content. It can be any element or React component you like.</p>
                <p>It can even be another Collapsible component. Check out the next section!</p>
            </Collapsible>

        );
    }

}
export default Author;

我已经安装了 react-collapsible ,我在 package.json

中有适当的依赖关系

当我尝试编译此代码时,我有编译错误:

Failed to compile.

./node_modules/react-collapsible/src/Collapsible.js
Module parse failed: Unexpected token (116:8)
You may need an appropriate loader to handle this file type.
|     if (this.props.triggerSibling && typeof 
this.props.triggerSibling === 'string') {
|       return (
|         <span className={`${this.props.classParentString}__trigger- 
sibling`}>{this.props.triggerSibling}</span>
|       )
|     } else if(this.props.triggerSibling) {

当然这只是项目的一部分,除了这一部分一切正常。我不知道我该怎么做,如果错误与代码的其他部分有关,这可能有用,请告诉我。

反应可折叠模块错了吗?我该怎么办?当我安装它时,我没有收到任何WARN,应该添加其他依赖

1 个答案:

答案 0 :(得分:0)

将导入更改为import Collapsible from "react-collapsible";

您要从src而不是已处理的dist进行导入。

如果您查看此模块的package.json,您会看到默认exported filedist/Collapsible.js