javascript - react-collapsible 编译失败
问题描述
我正在从事 spring+reactJS 项目,目前正在从事前端工作(该领域的初学者)。
通常我会尝试从“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) {
当然,这只是项目的一部分,除了这部分一切正常。我不知道我该怎么做,如果错误与代码的其他部分有关,这可能有用,请告诉我。
反应可折叠模块有问题吗?我该怎么办?当我安装它时,我没有收到任何警告,应该添加其他依赖项
解决方案
将您的导入更改为import Collapsible from "react-collapsible";
您正在从已处理的src
而不是dist
已处理的中导入。
如果您签出此模块的 package.json,您将看到默认导出的文件是dist/Collapsible.js
.
推荐阅读
- javascript - Webpack 观看模式 + Express Static 导致 Chrome 挂起?
- ruby-on-rails - 列出 FactoryBot 创建的记录
- python - 使用闭包来记住以前的函数调用
- c# - 将带有数据字节的内存流附加到 csv 中下载
- python - 如何计算外键对象可以使用多少次
- java - 对 BootstrapClassLoader java.lang java.io 感到困惑
- node.js - 在nodejs中安排推送通知时间
- flutter - Flutter:合并 2 InheritedWidget 作为 MaterialApp 的父级
- python - Python中的缺失值
- google-colaboratory - 在 Google Colab 中,当使用 wget 命令将文件从外部站点加载到 Google Drive 目录时,它会使用我的互联网还是 Colab 的互联网?