create-react-app - create-react-app 项目中的 dygraphs 缩小构建错误

标签 create-react-app dygraphs

我已将 dygraph 添加到一个使用 create-react-app 创建的大型现有项目中。一切运行良好,我正在使用通用语法导入 dygraphs:

import Dygraph from 'dygraphs';

但是,当我尝试使用 npm run build 构建项目时,dygraphs 的 ES6 位会导致构建失败:

Creating an optimized production build...
Failed to compile.

Failed to minify the code from this file:

        ..dev/node_modules/dygraphs/src/dygraph-utils.js:325

Read more here: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify

按照链接查看第 325 行,缩小器被 ES6 => 运算符绊倒。查看node_modules/dygraphs下,有srcsrc-es5目录。我将 src 重命名为 src-es6 并创建了一个符号链接(symbolic link):

src -> src-es5

使用此方法一切都运行和构建得很好,但它似乎不是最好的解决方案。提供的链接建议从 create-react-app 设备中弹出并自己处理构建,但这不是一个选项。

有什么更合适的方法来处理这个问题的建议吗?有没有特定的方法可以从 es5 src 目录导入 Dygraph

最佳答案

我可以确认 @danvk 建议的解决方法工作正常。

您需要做的就是转到位置 - node_modules/dygraphs/package.json 处的 package.json 并将 module 值从indexindex.es5 并且构建工作得很好。

在这个问题得到解决之前,这有点麻烦。已经有一张 this 的票开立了。

关于create-react-app - create-react-app 项目中的 dygraphs 缩小构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49434288/

相关文章:

reactjs - 警告 : Using UNSAFE_componentWillMount in strict mode is not recommended (upgrade to CRA 4. 0.2)

javascript - 使用 Dygraph 很难指向非常接近的时间序列点

javascript - 在 Dygraph.js 中隐藏标签

javascript - Dygraphs.js 未显示第二个值

javascript - dygraph 仅显示上个月的数据

sass - WebStorm 中的未知伪选择器 'export'

css - 为什么我的 CSS 样式不适用于页面?

reactjs - 无需重建即可将不同的环境变量传递给 React 应用程序

javascript - 错误 "Your cache folder contains root-owned files, due to a bug in previous versions of npm"而 "npx create-react-app example_app"

dygraphs - 限制y轴范围