node.js - 如何解决节点模块编译中的循环依赖?
问题描述
我正在使用纱线工作区并且有一个项目(proj1),它使用我编写的库(proj2),当我启动它时,它已经用 create-react-library 进行了初始化。我的库在某些组件中使用了 visx。一切都很好,直到我在 index.js 文件中添加了最后一行,导出了另一个使用 visx 构建的组件:
export { ConfigField } from './ConfigField';
export { ConfigPage } from './ConfigPage';
export { SaveButton } from './SaveButton';
export { PageLoadingIndicator } from './PageLoadingIndicator';
export { UsersPage } from './UsersPage';
export { AnalyticValue } from './AnalyticValue';
export { DonutChart } from './DonutChart';
export { SingleValueDonutChart } from './SingleValueDonutChart';
export { Alert } from './Alert';
export { FormDialog } from './FormDialog';
export { TimeSeriesChart } from './TimeSeriesChart';
不知何故,在添加此导出后,在构建 proj2 时会创建一个循环依赖项。我怀疑这与编译有 CJS 导入有关。
PS C:\usr\git\proj2> yarn
yarn install v1.22.5
warning package.json: No license field
[1/4] Resolving packages...
success Already up-to-date.
$ run-s build
yarn run v1.22.5
warning package.json: No license field
$ microbundle-crl --no-compress --format modern,cjs
Circular dependency: ..\node_modules\@visx\axis\esm\index.js -> ..\node_modules\@visx\axis\esm\axis\Axis.js -> ..\node_modules\@visx\axis\esm\axis\AxisRenderer.js -> ..\node_modules\@visx\axis\esm\index.js
Non-existent export 'TextProps' is imported from ..\node_modules\@visx\text\esm\types.js
Error: 'TextProps' is not exported by ..\node_modules\@visx\text\esm\types.js, imported by ..\node_modules\@visx\text\esm\Text.js
at C:\usr\git\proj1\node_modules\@visx\text\esm\Text.js:8:9
6: import useText from './hooks/useText';
7: import { TextProps } from './types';
8: export { TextProps } from './types';
^
9: var SVG_STYLE = {
10: overflow: 'visible'
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "build" exited with 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
如何解决这种循环依赖?有我应该使用的插件吗?
解决方案
解决了。这个问题实际上很基本。我意识到我是从@visx/axis
没有明确地在我的package.json
. 明确添加后,它可以工作。
推荐阅读
- quarkus - Quarkus 和 MongoPanache 中的本机图像问题
- pandas - 日复一日地排除具有某些价值的 ID
- r - 无法为 R 安装 Stringi(R-studio 1.1.456,OS X 10.15.2 Catalina)
- android - 标志 FLAG_ACTIVITY_CLEAR_TASK 清除与活动关联的任何任务。与活动无关的任务呢?
- java - 解释一下spring项目的结构?
- amazon-qldb - 1500 是并发 QLDB 事务的限制吗?
- linux - ASP.Net Core serilog 未在 Linux VM 中创建
- angularjs - 如何从模型中的数组中设置 ng-controller 值?
- javascript - 我的页面上有多个模态弹出窗口,当我单击提交时,我能够获取第一个模态弹出窗口的表单值,但不能获取其他表单值
- python - 如何计算字典中多个矩阵的均值/中值/标准差?