javascript - 使用流的 React 库会导致问题
问题描述
我对 js 和反应比较陌生,所以请多多包涵!create-react-app
我使用和 react开始了一个新项目16.12.0
。我安装了一个库,我猜它使用flow。尝试使用这个 ( npm install
) 库会给我以下 SynatError:
./node_modules/react-resize-aware/src/useResizeAware.js
SyntaxError: [...]\node_modules\react-resize-aware\src\useResizeAware.js: Unexpected token, expected "," (5:31)
3 | import ResizeListener from './ResizeListener';
4 |
> 5 | const defaultReporter = (target: ?HTMLElement) => ({
| ^
6 | width: target != null ? target.offsetWidth : null,
7 | height: target != null ? target.offsetHeight : null,
8 | });
我觉得这是我这边的一个问题,或者至少是我可以通过对项目的package.json
. 如果是这样,如果你能向我解释如何,我会很高兴。
//编辑:我尝试按照此处所述flow
添加到我的项目中,但它给了我同样的错误。有效的方法是将库的源代码复制到我的项目中,然后从这个本地版本中导入它。但我真的很想使用 npm 包,而不是自己维护本地版本的 lib。
非常感谢您!
解决方案
Silly me, I simply imported from the wrong path. I used
import moduleName from "lib-name/src";
instead of
import moduleNamefrom "lib-name";
推荐阅读
- dart - 如何禁用 Flutter 的 Navigator 类的返回操作
- r - R:基于以不同数据集中的点为中心的特定分布从数据集中采样
- numpy - 将 PCM 波形数据转换为 numpy 数组,反之亦然
- javascript - 如何在 Vue 应用程序中更新图表 js?
- python - 如何根据索引将单列中的 NaN 替换为 0
- python - 仅在按键事件后才在绘图循环中显示下一个绘图(Matplotlib 和 Python)
- java - 运行 Java 代码后从数据库中删除的记录
- c# - 无法加载文件或程序集“accord.video.ffmpeg.x64.dll”或其依赖项之一
- javascript - 循环显示 jQuery 对象以显示 3 个最新列表
- php - 当我尝试上传 30MB 文件时,“此页面无法正常工作”域名“当前无法处理此请求。HTTP ERROR 500”