javascript - ReactJS 库在更改 rollup.config.js 的 commonjs 函数时在导出它的项目中给出“ReferenceError: __extends is not defined”
问题描述
我正在做一个项目,我们还有一个库项目,其中包含项目中使用的所有通用组件。在这个库中,我必须添加一个使用materialUI
. 当我试图导出该组件时,我收到了错误:
[!] Error: 'ForwardRef' is not exported by node_modules\react-is\index.js
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
node_modules\@material-ui\utils\esm\getDisplayName.js (2:9)
1: import _typeof from "@babel/runtime/helpers/esm/typeof";
2: import { ForwardRef, Memo } from 'react-is'; // Simplified polyfill for IE 11 support
现在我可以通过改变 rollup.config.js 中的 commonjs 函数来解决这个问题,如下所示:
commonjs({
include: "node_modules/**",
namedExports: {
"node_modules/react-is/index.js": ["ForwardRef", "Memo"],
},
}),
这反过来又造成了另一个错误。当我从一开始就直接在主项目上重新安装库时,我得到了错误。
Uncaught ReferenceError: _extends is not defined
at exactProp (index.es.js:14590)
at Module.<anonymous> (index.es.js:18939)
at Module../node_modules/bt-react-lib/dist/index.es.js (index.es.js:25529)
at __webpack_require__ (bootstrap:782)
at fn (bootstrap:150)
at Module../src/components/main/Main.js (Dashboard.js:52)
at __webpack_require__ (bootstrap:782)
at fn (bootstrap:150)
at Module../src/App.js (log$:24)
at __webpack_require__ (bootstrap:782)
at fn (bootstrap:150)
at Module../src/index.js (index.css?02e3:45)
at __webpack_require__ (bootstrap:782)
at fn (bootstrap:150)
at Object.1 (objects.js:1)
at __webpack_require__ (bootstrap:782)
at checkDeferredModules (bootstrap:45)
at Array.webpackJsonpCallback [as push] (bootstrap:32)
at main.chunk.js:1
我想再次与materialUI有关。有人以前有过这个吗?
解决方案
您可能应该将材料视为对等依赖项,以及 react 和 react dom。这是在同一问题上帮助我的样板示例。
首先修改package.json
并移动材料,"peerDependencies": {... }
然后您必须安装rollup-plugin-peer-deps-external
并将其添加到您的汇总文件中。现在您可以撤消命名的导出,您应该已经完成了。
推荐阅读
- python - 无法在 Python 中删除辅助框架
- macos - 如何方便地键入 Cmd+?在 Mac 键盘上?
- python - 删除所有空格
- kubernetes - 基于副本的 Kubernetes 容器亲和性?
- javascript - 如何使用扩展语法删除第一个数组元素
- mysql - mySQL - 取决于其他列的唯一性约束
- python - 如何在调制文件中传递变量?
- node.js - MongoDB:使用嵌套的 $group 聚合
- ruby-on-rails - 在 Rails 5.2.1 中安装 Webpacker 后,立即出现“无法修改冻结数组”错误
- angular - Promise 和 Observables 使用 async-await 模式上传多个文件——Ionic 3,Firebase