微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何解决节点模块编译中的循环依赖?

如何解决如何解决节点模块编译中的循环依赖?

我正在使用 yarn 工作区,并且有一个项目 (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 中明确地使用它。 ? 明确添加后,就可以了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。